Révision 247

Pi/C/MPI/Pi_MPI.c (revision 247)
1 1
//
2 2
// Estimation of Pi using Monte Carlo exploration process
3
// gcc -std=c99 -O3 -o Pi Pi.c -lm 
4
// Emmanuel Quemener <emmanuel.quemener@ens-lyon.fr>
3
// Cecill v2 Emmanuel QUEMENER <emmanuel.quemener@gmail.com>
4
// gcc -std=c99 -O3 -o Pi_MPI Pi_MPI.c -lm
5 5

  
6 6
// Needed for gethostname
7
#define _BSD_SOURCE
7
#define _DEFAULT_SOURCE
8 8
#include <sys/unistd.h>
9 9

  
10 10
#include <math.h>
......
13 13
#include <limits.h>
14 14
#include <mpi.h>
15 15
#include <stddef.h>
16

  
17 16
#include <sys/time.h>
18 17

  
19 18
// Marsaglia RNG very simple implementation
......
144 143

  
145 144
  unsigned int seed_z=362436069,seed_w=52128862;
146 145
  LENGTH iterations=ITERATIONS,inside[8192],insides,part_inside,part_iterations;
147
  int numtasks,rank,rc,tag=1,i;
148
  float pi;
146
  int NumberProcesses,rank,rc,tag=1,i;
149 147

  
150 148
  char hostname[128];
151 149

  
......
162 160
    MPI_Abort(MPI_COMM_WORLD, rc);
163 161
  }
164 162

  
165
  MPI_Comm_size(MPI_COMM_WORLD,&numtasks);
163
  MPI_Comm_size(MPI_COMM_WORLD,&NumberProcesses);
166 164
  MPI_Comm_rank(MPI_COMM_WORLD,&rank);
167 165

  
168 166
  const int nitems=2;
......
184 182
  MPI_Type_commit(&mpi_result_type);
185 183
    
186 184
  if (rank==0) {
187
    
185

  
186
    struct timeval tv1,tv2;
187

  
188 188
    if (argc > 1) {
189 189
      iterations=(LENGTH)atoll(argv[1]);
190 190
    }
......
201 201
    printf ("\tMax long = %ld\n", LONG_MAX);
202 202
    printf ("\tMax long long = %lld\n\n", LLONG_MAX);
203 203
    
204
    part_iterations=((iterations%numtasks) == 0) ? iterations/numtasks:iterations/numtasks+1 ;
204
    part_iterations=((iterations%NumberProcesses) == 0) ? iterations/NumberProcesses:iterations/NumberProcesses+1 ;
205

  
206
    gettimeofday(&tv1, NULL);
205 207
    
206 208
    // Split part of code
207
    for (i=1;i<numtasks;i++) {
209
    for (i=1;i<NumberProcesses;i++) {
208 210
      
209 211
#ifdef LONG
210 212
      rc = MPI_Send(&part_iterations, 1, MPI_LONG_LONG, i, tag, 
......
226 228
	     hostname,rank,(long long)insides,useconds);
227 229
      
228 230
    // Join part of code
229
      for (i=1;i<numtasks;i++) {
231
      for (i=1;i<NumberProcesses;i++) {
230 232

  
231 233
	result recv;
232 234
	
......
241 243
	insides+=inside[i];
242 244
      }
243 245
      
244
      pi=4.*(float)insides/(float)(part_iterations*numtasks);
246
      float pi=4.*(float)insides/(float)(part_iterations*NumberProcesses);
247

  
248
      gettimeofday(&tv2, NULL);
245 249
      
246
      printf("\n\tPi=%.40f\n\twith error %.40f\n\twith %lld iterations\n\n",pi,
247
	     fabs(pi-4*atan(1.))/pi,(long long)iterations);
250
      double elapsed=(double)((tv2.tv_sec-tv1.tv_sec) * 1000000L +
251
			      (tv2.tv_usec-tv1.tv_usec))/1000000;
252
      
253
      double itops=(double)(part_iterations*NumberProcesses)/elapsed;
254
  
255
      printf("\nParallelRate %i\nElapsed Time %.2f\nItops %.0f\nLogItops %.2f\n",NumberProcesses,elapsed,itops,log10(itops));
248 256

  
257
      LENGTH total=((iterations%NumberProcesses)==0)?iterations:(iterations/NumberProcesses+1)*NumberProcesses;
258

  
259
      printf("Inside/Total %ld %ld\nPi estimation %f\n\n",(long int)insides,(long int)total,(4.*(float)insides/total));
260
      
249 261
  }
250 262
  else
251 263
    {
......
284 296

  
285 297
  MPI_Type_free(&mpi_result_type);  
286 298
  MPI_Finalize();
299

  
287 300
}
Pi/C/MPI/Pi_aMPI.c (revision 247)
1 1
//
2 2
// Estimation of Pi using Monte Carlo exploration process
3
// Cecill v2 Emmanuel QUEMENER <emmanuel.quemener@gmail.com>
3 4
// gcc -std=c99 -O3 -o Pi_aMPI Pi_aMPI.c -lm 
4
// Emmanuel Quemener <emmanuel.quemener@ens-lyon.fr>
5 5

  
6 6
// Needed for gethostname
7
#define _BSD_SOURCE
7
#define _DEFAULT_SOURCE
8 8
#include <sys/unistd.h>
9 9

  
10 10
#include <math.h>
......
13 13
#include <limits.h>
14 14
#include <mpi.h>
15 15
#include <stddef.h>
16

  
17 16
#include <sys/time.h>
18 17

  
19 18
// Marsaglia RNG very simple implementation
......
145 144

  
146 145
  unsigned int seed_z=362436069,seed_w=52128862;
147 146
  LENGTH iterations=ITERATIONS,inside[8192],insides,part_inside,part_iterations;
148
  int numtasks,rank,rc,tag=1,i;
149
  float pi;
147
  int NumberProcesses,rank,rc,tag=1,i;
150 148

  
151 149
  char hostname[128];
152 150

  
......
166 164
    MPI_Abort(MPI_COMM_WORLD, rc);
167 165
  }
168 166

  
169
  MPI_Comm_size(MPI_COMM_WORLD,&numtasks);
167
  MPI_Comm_size(MPI_COMM_WORLD,&NumberProcesses);
170 168
  MPI_Comm_rank(MPI_COMM_WORLD,&rank);
171 169
  
172
  MPI_Comm_size(MPI_COMM_WORLD,&numtasks);
170
  MPI_Comm_size(MPI_COMM_WORLD,&NumberProcesses);
173 171
  MPI_Comm_rank(MPI_COMM_WORLD,&rank);
174 172

  
175 173
  const int nitems=2;
......
191 189
  MPI_Type_commit(&mpi_result_type);
192 190

  
193 191
  if (rank==0) {
192

  
193
    struct timeval tv1,tv2;
194 194
    
195 195
    if (argc > 1) {
196 196
      iterations=(LENGTH)atoll(argv[1]);
......
206 206
    
207 207
    printf ("\tMax int = %u\n", INT_MAX);
208 208
    printf ("\tMax long = %ld\n", LONG_MAX);
209
    printf ("\tMax long long = %lld\n", LLONG_MAX);
209
    printf ("\tMax long long = %lld\n\n", LLONG_MAX);
210 210
    
211
    part_iterations=((iterations%numtasks) == 0) ? iterations/numtasks:iterations/numtasks+1 ;
211
    part_iterations=((iterations%NumberProcesses) == 0) ? iterations/NumberProcesses:iterations/NumberProcesses+1 ;
212

  
213
    gettimeofday(&tv1, NULL);
212 214
    
213 215
    // Split part of code
214
    for (i=1;i<numtasks;i++) {
216
    for (i=1;i<NumberProcesses;i++) {
215 217
      
216 218
#ifdef LONG
217 219
      rc = MPI_Isend(&part_iterations, 1, MPI_LONG_LONG, i, tag, 
......
221 223
		     MPI_COMM_WORLD,&RequestSend);
222 224
#endif      
223 225
    }
224
    if (numtasks>1) {
226
    if (NumberProcesses>1) {
225 227
      MPI_Wait(&RequestSend, &Stat);
226 228
    }
227 229
    
......
236 238
	     hostname,rank,(long long)insides,useconds);
237 239
      
238 240
    // Join part of code
239
      for (i=1;i<numtasks;i++) {
241
      for (i=1;i<NumberProcesses;i++) {
240 242

  
241 243
	result recv;
242 244
	
243 245
	rc = MPI_Irecv(&recv, 1, mpi_result_type, i, tag, 
244 246
		      MPI_COMM_WORLD, &RequestRecv2);
245 247

  
246
	if (numtasks>1) {
248
	if (NumberProcesses>1) {
247 249
	    MPI_Wait(&RequestRecv2, &Stat);
248 250
	}
249 251
	
......
255 257
	insides+=inside[i];
256 258
      }
257 259
      
258
      pi=4.*(float)insides/(float)(part_iterations*numtasks);
260
      gettimeofday(&tv2, NULL);
259 261
      
260
      printf("\n\tPi=%.40f\n\twith error %.40f\n\twith %lld iterations\n\n",pi,
261
	     fabs(pi-4*atan(1.))/pi,(long long)iterations);
262
      double elapsed=(double)((tv2.tv_sec-tv1.tv_sec) * 1000000L +
263
			      (tv2.tv_usec-tv1.tv_usec))/1000000;
264
      
265
      double itops=(double)(part_iterations*NumberProcesses)/elapsed;
266
  
267
      printf("\nParallelRate %i\nElapsed Time %.2f\nItops %.0f\nLogItops %.2f\n",NumberProcesses,elapsed,itops,log10(itops));
262 268

  
269
      LENGTH total=((iterations%NumberProcesses)==0)?iterations:(iterations/NumberProcesses+1)*NumberProcesses;
270

  
271
      printf("Inside/Total %ld %ld\nPi estimation %f\n\n",(long int)insides,(long int)total,(4.*(float)insides/total));
272
      
263 273
  }
264 274
  else
265 275
    {
Pi/C/Simple/Pi_Simple.c (revision 247)
159 159
  
160 160
  double itops=(double)(iterations)/elapsed;
161 161
  
162
  printf("Inside/Total %lld %lld\nElapsed Time %.2f\nItops %.0f\nPi estimation %f\n\n",inside,iterations,elapsed,itops,(4.*(float)inside/(float)(iterations)));
162
  printf("Inside/Total %lld %lld\nElapsed Time %.2f\nItops %.0f\nLogItops %.2f\nPi estimation %f\n\n",inside,iterations,elapsed,itops,log10(itops),(4.*(float)inside/(float)(iterations)));
163 163

  
164
  printf("\n\n");
165

  
166 164
  return 0;
167 165
  
168 166
}
Pi/C/OpenMP/Pi_OpenMP.c (revision 247)
1 1
//
2 2
// Estimation of Pi using Monte Carlo exploration process
3 3
// Cecill v2 Emmanuel QUEMENER <emmanuel.quemener@gmail.com>
4
// gcc -std=c99 -O3 -o Pi Pi.c -lm 
4
// gcc -std=c99 -O3 -o Pi_OpenMP Pi_OpenMP.c -lm 
5 5
//
6 6

  
7 7
#include <math.h>
......
154 154
  
155 155
  double itops=(double)(ParallelRate*IterationsEach)/elapsed;
156 156
  
157
  printf("ParallelRate %i\nElapsed Time %.2f\nItops %.0f\n",ParallelRate,elapsed,itops);
157
  printf("ParallelRate %i\nElapsed Time %.2f\nItops %.0f\nLogItops %.2f\n",ParallelRate,elapsed,itops,log10(itops));
158 158

  
159 159
  free(inside);
160 160
  
......
169 169
  
170 170
  if (argc > 1) {
171 171
    iterations=(LENGTH)atoll(argv[1]);
172
    ParallelRate=atoi(argv[2]);
172
    if (argc > 2) {
173
      ParallelRate=atoi(argv[2]);
174
    }
173 175
  }
174 176
  else {
175 177
    printf("\n\tPi : Estimate Pi with Monte Carlo exploration\n\n");
Pi/C/Hybrid/Pi_Hybrid.c (revision 247)
1 1
//
2
// Estimation of Pi using Monte Carlo exploration process
3
// gcc -std=c99 -O3 -o Pi Pi.c -lm 
4
// Emmanuel Quemener <emmanuel.quemener@ens-lyon.fr>
5
// Cecill v2
2
// Estimation of Pi using Monte Carlo exploration process using OpenMP & MPI
3
// Cecill v2 Emmanuel QUEMENER <emmanuel.quemener@gmail.com>
4
// gcc -std=c99 -O3 -o Pi_Hybrid Pi_Hybrid.c -lm 
6 5

  
7 6
// Needed for gethostname
8
#define _BSD_SOURCE
7
#define _DEFAULT_SOURCE
9 8
#include <sys/unistd.h>
10 9

  
11 10
#include <math.h>
......
159 158
  LENGTH iterations=ITERATIONS,insideMPI[8192],insideOpenMP[1024],
160 159
    part_inside=0,part_iterations,insides=0;
161 160
  int numtasks,rank,rc,tag=1,i;
162
  float pi;
163 161
  
164 162
  // Hostname supposed to be <128 characters
165 163
  char hostname[128];
......
207 205
  MPI_Type_commit(&mpi_result_type);
208 206
  
209 207
  if (rank==0) {
208

  
209
    struct timeval tv1,tv2;
210 210
    
211 211
    if (argc > 1) {
212 212
      iterations=(LENGTH)atoll(argv[1]);
......
234 234
    send.iterations=part_iterations;
235 235
    send.process=process;
236 236

  
237
    gettimeofday(&tv1, NULL);
238
        
237 239
    // Split part of code
238 240
    for (i=1;i<numtasks;i++) {      
239 241
      rc = MPI_Send(&send, 1, mpi_node_type, i, tag, MPI_COMM_WORLD);
......
280 282
      insides+=insideMPI[i];
281 283
    }
282 284
    
283
    pi=4.*(float)insides/(float)(part_iterations*numtasks*process);
285
    gettimeofday(&tv2, NULL);
286

  
287
    double elapsed=(double)((tv2.tv_sec-tv1.tv_sec) * 1000000L +
288
			      (tv2.tv_usec-tv1.tv_usec))/1000000;
284 289
    
285
    printf("\n\tPi=%.40f\n\twith error %.40f\n\twith %lld iterations\n\n",pi,
286
	   fabs(pi-4*atan(1.))/pi,(long long)(part_iterations*numtasks*process));
290
    double itops=(double)(part_iterations*numtasks)/elapsed;
287 291
    
292
    printf("\nParallelRate %i\nElapsed Time %.2f\nItops %.0f\nLogItops %.2f\n",numtasks*process,elapsed,itops,log10(itops));
293
    
294
    LENGTH total=((iterations%numtasks)==0)?iterations:(iterations/numtasks+1)*numtasks;
295

  
296
    printf("Inside/Total %ld %ld\nPi estimation %f\n\n",(long int)insides,(long int)total,(4.*(float)insides/total));
297
    
288 298
  }
289 299
  else
290 300
    {
BLAS/xGEMM/xGEMM.c (revision 247)
38 38
#include <acml.h>
39 39
#else
40 40
#include <cblas.h>
41
// #include <blaswrap.h>
41
//#include <blaswrap.h>
42 42
#endif
43 43

  
44 44
#ifdef CLBLAS

Formats disponibles : Unified diff