Révision 82

Pi/C/OpenMP/XeonPhi/Pi_OpenMP.c (revision 82)
1 1
//
2 2
// Estimation of Pi using Monte Carlo exploration process
3
// gcc -std=c99 -O3 -o Pi Pi.c -lm 
3
// Exploit OpenMP on Xeon Phi
4
// source /opt/intel/bin/compilervars.sh intel64
5
// icpc -std=c99 -O3 -o Pi Pi.c -lm 
4 6
//
5 7

  
6 8
#include <math.h>
......
19 21

  
20 22
#define MWCfp MWC * 2.328306435454494e-10f
21 23
#define KISSfp KISS * 2.328306435454494e-10f
24
#define SHR3fp SHR3 * 2.328306435454494e-10f
25
#define CONGfp CONG * 2.328306435454494e-10f
22 26

  
23 27
#define ITERATIONS 1000000000
24 28

  
......
35 39

  
36 40
LENGTH MainLoopGlobal(LENGTH iterations,unsigned int seed_w,unsigned int seed_z)
37 41
{
42
#if defined TCONG
43
   unsigned int jcong=seed_z;
44
#elif defined TSHR3
45
   unsigned int jsr=seed_w;
46
#elif defined TMWC
38 47
   unsigned int z=seed_z;
39 48
   unsigned int w=seed_w;
40

  
49
#elif defined TKISS
50
   unsigned int jcong=seed_z;
51
   unsigned int jsr=seed_w;
52
   unsigned int z=seed_z;
53
   unsigned int w=seed_w;
54
#endif
55
  
41 56
   LENGTH total=0;
42 57

  
43 58
   for (LENGTH i=0;i<iterations;i++) {
44 59

  
45
      float x=MWCfp ;
46
      float y=MWCfp ;
60
#if defined TINT32
61
    #define THEONE 1073741824
62
    #if defined TCONG
63
        unsigned int x=CONG>>17 ;
64
        unsigned int y=CONG>>17 ;
65
    #elif defined TSHR3
66
        unsigned int x=SHR3>>17 ;
67
        unsigned int y=SHR3>>17 ;
68
    #elif defined TMWC
69
        unsigned int x=MWC>>17 ;
70
        unsigned int y=MWC>>17 ;
71
    #elif defined TKISS
72
        unsigned int x=KISS>>17 ;
73
        unsigned int y=KISS>>17 ;
74
    #endif
75
#elif defined TINT64
76
    #define THEONE 4611686018427387904
77
    #if defined TCONG
78
        unsigned long x=(unsigned long)(CONG>>1) ;
79
        unsigned long y=(unsigned long)(CONG>>1) ;
80
    #elif defined TSHR3
81
        unsigned long x=(unsigned long)(SHR3>>1) ;
82
        unsigned long y=(unsigned long)(SHR3>>1) ;
83
    #elif defined TMWC
84
        unsigned long x=(unsigned long)(MWC>>1) ;
85
        unsigned long y=(unsigned long)(MWC>>1) ;
86
    #elif defined TKISS
87
        unsigned long x=(unsigned long)(KISS>>1) ;
88
        unsigned long y=(unsigned long)(KISS>>1) ;
89
    #endif
90
#elif defined TFP32
91
    #define THEONE 1.0f
92
    #if defined TCONG
93
        float x=CONGfp ;
94
        float y=CONGfp ;
95
    #elif defined TSHR3
96
        float x=SHR3fp ;
97
        float y=SHR3fp ;
98
    #elif defined TMWC
99
        float x=MWCfp ;
100
        float y=MWCfp ;
101
    #elif defined TKISS
102
      float x=KISSfp ;
103
      float y=KISSfp ;
104
    #endif
105
#elif defined TFP64
106
    #define THEONE 1.0f
107
    #if defined TCONG
108
        double x=(double)CONGfp ;
109
        double y=(double)CONGfp ;
110
    #elif defined TSHR3
111
        double x=(double)SHR3fp ;
112
        double y=(double)SHR3fp ;
113
    #elif defined TMWC
114
        double x=(double)MWCfp ;
115
        double y=(double)MWCfp ;
116
    #elif defined TKISS
117
        double x=(double)KISSfp ;
118
        double y=(double)KISSfp ;
119
    #endif
120
#endif
47 121

  
48 122
      // Matching test
49
      int inside=((x*x+y*y) < 1.0f) ? 1:0;
123
      unsigned long inside=((x*x+y*y) < THEONE) ? 1:0;
50 124
      total+=inside;
125

  
51 126
   }
52 127

  
53 128
   return(total);
......
55 130

  
56 131
LENGTH splitter(int process,int seed_w,int seed_z,LENGTH iterations) {
57 132

  
58
  LENGTH inside[1024],insides=0;
133
  LENGTH inside[4096],insides=0;
59 134
  int i;
60 135
  
61 136
#pragma omp target device(0)
62 137
#pragma omp teams num_teams(60) thread_limit(4)
138
// #pragma omp parallel for
63 139
#pragma omp distribute
64 140
  for (int i=0 ; i<process; i++) {
65
    inside[i]=MainLoopGlobal(iterations/process,seed_w+process,seed_z+process);
66
    //    printf("\tFound %lld for process %i\n",(long long)inside[i],i);
141
    inside[i]=MainLoopGlobal(iterations/process,seed_w+i,seed_z+i);
67 142
  }
68
  //printf("\n");
69 143

  
70 144
  for (int i=0 ; i<process; i++) {
145
    printf("\tFound %lld for process %i\n",(long long)inside[i],i);
71 146
    insides+=inside[i];
72 147
  }
148
  printf("\n");
73 149
  
74 150
  return(insides);
75 151
}
......
78 154

  
79 155
  unsigned int seed_w=10,seed_z=10,process=PROCESS;
80 156
  LENGTH iterations=ITERATIONS;
81
  LENGTH inside[1024],insides=0;
157
  LENGTH insides=0;
82 158

  
83 159
  if (argc > 1) {
84 160
    iterations=(LENGTH)atoll(argv[1]);
Pi/C/OpenMP/XeonPhi/bench.sh (revision 82)
1 1
#!/bin/bash
2 2

  
3 3
EXE=Pi_OpenMP_LONG
4
ITERATIONS=10000000000
4
ITERATIONS=100000000000
5 5
MYTIME=/usr/bin/time
6 6

  
7 7
REPEAT=10
8
PROCESS=480
8
PROCESS=960
9 9

  
10 10
[ ! $1 == '' ] && EXE=$1
11 11
[ ! $2 == '' ] && ITERATIONS=$2
12 12
[ ! $3 == '' ] && PROCESS=$3
13 13

  
14
LOGFILE=${EXE}_${HOSTNAME}_${ITERATIONS}.log
14
LOGFILE=${EXE}_${HOSTNAME}_${ITERATIONS}_$(date "+%Y%m%d").log
15 15

  
16 16
> $LOGFILE
17
p=1
17
p=3
18 18
while [ $p -le $PROCESS ]
19 19
do
20 20
    export OMP_NUM_THREADS=$p
......
24 24
    while [ $i -le $REPEAT ]
25 25
    do 
26 26
        echo -ne "$i "
27
        $MYTIME ./$EXE $ITERATIONS $p >> $LOGFILE 2>&1 
27
        $MYTIME hwloc-bind -p pu:1 ./$EXE $ITERATIONS $p >> $LOGFILE 2>&1 
28
	sleep 10
28 29
        i=$(($i+1))
29 30
    done
30 31
    echo
Pi/C/OpenMP/XeonPhi/Makefile (revision 82)
1
EXECUTABLE=Pi_OpenMP_LONG Pi_OpenMP_INT
2

  
3 1
SOURCE=Pi_OpenMP.c
4 2

  
3
COMPUTING=INT32 INT64 FP32 FP64
4
MARSAGLIA=SHR3 CONG MWC KISS
5

  
5 6
CC=icpc
6 7
CFLAGS=-Wall -O3 -openmp -g
7 8
LIBRARY=-lm
8 9

  
9
all: $(EXECUTABLE)
10
all: $(SOURCE)
10 11

  
11
Pi_OpenMP_LONG: $(SOURCE)
12
	$(foreach TVAR,$(COMPUTING),$(foreach TRND,$(MARSAGLIA),$(CC) $(CFLAGS) -DT$(TVAR) -DT$(TRND) -DLONG -DTIME -o $(<:.c=)_$(TVAR)_$(TRND) $< $(LIBRARY); ) )
12 13

  
13
	$(CC) $(CFLAGS) $(DIRECTIVES) -DLONG -o $@ $< $(LIBRARY)
14

  
15
Pi_OpenMP_INT: $(SOURCE)
16

  
17
	$(CC) $(CFLAGS) $(DIRECTIVES) -DINTEGER -o $@ $< $(LIBRARY)
18

  
19 14
.PHONY: clean check mrproper
20 15

  
21
mrproper: 
22
	rm -rf $(EXECUTABLE)
16
mrproper:
17
	rm -rf $(foreach TVAR,$(TVARS),$(foreach TRND,$(MARSAGLIA),$(<:.c=)_$(TVAR)_$(TRND) ) )
23 18
	find . -name "*~" -exec rm {} \;
24 19

  
25 20
clean:

Formats disponibles : Unified diff