Révision 29

Pi/C/OpenMP/Pi_OpenMP.c (revision 29)
7 7
#include <stdio.h>
8 8
#include <stdlib.h>
9 9
#include <omp.h>
10
#include <limits.h>
10 11

  
11 12
// Marsaglia RNG very simple implementation
12 13
#define znew  ((z=36969*(z&65535)+(z>>16))<<16)
......
24 25
#define PROCESS 4
25 26

  
26 27
#ifdef LONG
27
#define LENGTH unsigned long
28
#define LENGTH long long
28 29
#else
29
#define LENGTH unsigned int
30
#define LENGTH int
30 31
#endif
31 32

  
32 33
LENGTH MainLoopGlobal(LENGTH iterations,unsigned int seed_w,unsigned int seed_z)
......
65 66
    printf("\t\t#2 : number of process (default 4)\n\n");
66 67
  }
67 68

  
69
  printf ("\n\tInformation about architecture:\n\n");
70

  
71
  printf ("\tSizeof int = %lld bytes.\n", (long long)sizeof(int));
72
  printf ("\tSizeof long = %lld bytes.\n", (long long)sizeof(long));
73
  printf ("\tSizeof long long = %lld bytes.\n\n", (long long)sizeof(long long));
74

  
75
  printf ("\tMax int = %u\n", INT_MAX);
76
  printf ("\tMax long = %ld\n", LONG_MAX);
77
  printf ("\tMax long long = %lld\n\n", LLONG_MAX);
78

  
68 79
#pragma omp parallel for
69 80
  for (int i=0 ; i<process; i++) {
70 81
    inside[i]=MainLoopGlobal(iterations/process,seed_w,seed_z);
71
    printf("\tFound %lu for process %i\n",(unsigned long)inside[i],i);
82
    printf("\tFound %lld for process %i\n",(long long)inside[i],i);
72 83
  }
73 84
  printf("\n");
74 85

  
......
78 89
  
79 90
  float pi=4.*(float)insides/(float)iterations;
80 91

  
81
  printf("\tPi=%f with error %f and %lu iterations\n\n",pi,
82
         fabs(pi-4*atan(1))/pi,(unsigned long)iterations);
92
  printf("\tPi=%f with error %f and %lld iterations\n\n",pi,
93
         fabs(pi-4*atan(1))/pi,(long long)iterations);
83 94
  
84 95
}

Formats disponibles : Unified diff