Programowanie w systemie UNIX/CPU: Różnice pomiędzy wersjami
Usunięta treść Dodana treść
Nie podano opisu zmian |
m →Wypełnianie tablicy: pętle |
||
Linia 151:
</syntaxhighlight>
===Zagnieżdzone pętle ( ang. nested loops)===
<syntaxhighlight lang=c>
/*
C program that uses nested for loops
gcc o.c -Wall -fopenmp
./a.out
i = 10000 xMax*yMax = 10000
i = 444514 = 0.444514 *xMax*yMax where xMax*yMax = 1000000 // no reduction
i = 437097 = 0.437097*(xMax*yMax) where xMax*yMax = 1000000
i = 1000000 = 1.000000*(xMax*yMax) where xMax*yMax = 1000000 // reduction
*/
#include <stdio.h>
#include <stdlib.h>
#include <omp.h> // OpenMP
int i= 0;
int main()
{
int x;
int xMax = 1000;
int y;
int yMax = 1000;
int all = xMax*yMax;
#pragma omp parallel for collapse(2) schedule(dynamic) reduction(+:i)
for (x = 0; x < xMax; x++) {
for (y = 0; y < yMax; y++)
{i++;}
}
printf("i = %d = %f*(xMax*yMax) \t where xMax*yMax = %d\n", i, (double)i/all, all);
return 0;
}
</syntaxhighlight>
===Wypełnianie tablicy===
Linia 192 ⟶ 246:
</syntaxhighlight>
===zbiór Mandelbrota===
|