#include "stdafx.h"
#include <omp.h>
#include <iostream>
#include <Windows.h>
#include <vector>
int main(int argc, char* argv[])
{

	setlocale(0, "");
	int n1, m1;
	std::cin >> n1 >> m1;
	std::vector<std::vector<int> > A(n1, std::vector<int>(m1));
	int  i, j, n;
	float sum = 0.0;
	for (i = 0; i<n1; i++) {
		for (j = 0; j<m1; j++)
			A[i][j] = rand() % 20 + 1;
	}
	std::cout << "Source array" << "\n";
	for (i = 0; i<n1; i++) {
		for (j = 0; j<m1; j++)
			printf("%d ", A[i][j]);
		std::cout << "\n";
	}
	std::cout << "\n";
	omp_set_num_threads(15);
	double start = omp_get_wtime();
#pragma omp parallel shared(A) private(i, j, n)
	{

		n = omp_get_thread_num();
#pragma omp for
		for (i = 0; i<n1; i++)
		{
			for (j = 0; j<m1; j++)
				sum += A[i][j];
			std::cout << "Thread " << n << ", current sum " << sum << "\n";
		}
	}
	double end = omp_get_wtime();
	std::cout << "\n";
	std::cout << "All sum = " << sum << "\n";
	std::cout << "Time run = " << end - start << "\n";
	system("PAUSE");
	return 0;
}
