Skip to content

Instantly share code, notes, and snippets.

@auduchinok
Created May 21, 2015 14:03
Show Gist options
  • Save auduchinok/fafd34431a709864fcf2 to your computer and use it in GitHub Desktop.
Save auduchinok/fafd34431a709864fcf2 to your computer and use it in GitHub Desktop.
Matrix
#include "stdafx.h"
#include <iostream>
#include <omp.h>
using namespace std;
int main()
{
const int n = 10;
int *mArray = new int[n * n];
int **m = new int*[n];
for (int i = 0; i < n; i++)
{
m[i] = &mArray[n * i];
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
m[i][j] = i * n + j;
cout << m[i][j] << " ";
}
cout << endl;
}
int max_value = 0;
int threads_number = 2;
#pragma omp parallel for reduction(max: max_value)
for (int i = 0; i < n * n; i++)
{
if (mArray[i] > max_value)
{
max_value = mArray[i];
}
}
cout << "max: " << max_value << endl;
cin.get();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment