-
Notifications
You must be signed in to change notification settings - Fork 0
/
gol_omp.cpp
37 lines (34 loc) · 1.15 KB
/
gol_omp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "gol.hpp"
#include <iostream>
#include <cstdlib>
using namespace std;
void step_omp(int **__restrict__ & matrix, int ** __restrict__ & matrixOld, int n, int m, int nw) {
int i,j;
#pragma omp parallel num_threads(nw) shared(matrix,matrixOld) private(i,j) firstprivate(n,m)
{
//#pragma omp single
#pragma omp for schedule(static)
for(i=1; i<n-1; i++) {
//cout<<"ciclo: "<<i<<" ";
//#pragma omp simd
for(j=1; j<m-1; j++) {
matrixOld[i][j] = matrix[i-1][j-1]+matrix[i-1][j]+matrix[i-1][j+1];
matrixOld[i][j] += matrix[i][j-1]+matrix[i][j+1];
matrixOld[i][j] += matrix[i+1][j-1]+matrix[i+1][j]+matrix[i+1][j+1];
}
}
//#pragma omp single
#pragma omp for schedule(static)
for(i=1; i<n-1; i++) {
//#pragma omp simd
for(j=1; j<m-1; j++) {
bool val=0;
if(matrixOld[i][j] == 3)
val = 1;
else if(matrixOld[i][j] == 2)
val = matrix[i][j];
matrix[i][j] = val;
}
}
}
}