Révision 10 Pi/C/OpenMP/Pi_OpenMP.c
Pi_OpenMP.c (revision 10) | ||
---|---|---|
21 | 21 |
|
22 | 22 |
#define ITERATIONS 1000000000 |
23 | 23 |
|
24 |
#define PROCESS 8
|
|
24 |
#define PROCESS 4
|
|
25 | 25 |
|
26 | 26 |
#ifdef LONG |
27 | 27 |
#define LENGTH unsigned long |
... | ... | |
51 | 51 |
|
52 | 52 |
int main(int argc, char *argv[]) { |
53 | 53 |
|
54 |
unsigned int seed_w=10,seed_z=10; |
|
54 |
unsigned int seed_w=10,seed_z=10,process=PROCESS;
|
|
55 | 55 |
LENGTH iterations=ITERATIONS; |
56 | 56 |
LENGTH inside[1024],insides=0; |
57 | 57 |
|
58 | 58 |
if (argc > 1) { |
59 | 59 |
iterations=(LENGTH)atol(argv[1]); |
60 |
process=atoi(argv[2]); |
|
60 | 61 |
} |
61 | 62 |
else { |
62 |
printf("\n\tPi : Estimate Pi with Monte Carlo exploration\n\n\t\t#1 : number of iterations (default 1 billion)\n\n"); |
|
63 |
printf("\n\tPi : Estimate Pi with Monte Carlo exploration\n\n"); |
|
64 |
printf("\t\t#1 : number of iterations (default 1 billion)\n"); |
|
65 |
printf("\t\t#2 : number of process (default 4)\n\n"); |
|
63 | 66 |
} |
64 | 67 |
|
65 | 68 |
#pragma omp parallel for |
66 |
for (int i=0 ; i<PROCESS; i++) {
|
|
67 |
inside[i]=MainLoopGlobal(iterations/PROCESS,seed_w,seed_z);
|
|
68 |
printf("%lu\n",inside[i]);
|
|
69 |
for (int i=0 ; i<process; i++) {
|
|
70 |
inside[i]=MainLoopGlobal(iterations/process,seed_w,seed_z);
|
|
71 |
printf("\tFound %lu for process %i\n",(unsigned long)inside[i],i);
|
|
69 | 72 |
} |
73 |
printf("\n"); |
|
70 | 74 |
|
71 |
for (int i=0 ; i<PROCESS; i++) {
|
|
75 |
for (int i=0 ; i<process; i++) {
|
|
72 | 76 |
insides+=inside[i]; |
73 | 77 |
} |
74 | 78 |
|
Formats disponibles : Unified diff