Changes between Version 66 and Version 67 of DRM4G/Tutorial


Ignore:
Timestamp:
Jun 28, 2016 9:28:12 AM (6 years ago)
Author:
carlos
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DRM4G/Tutorial

    v66 v67  
    261261
    262262* C code :
    263 {{{
    264 #!cpp
    265 #include "mpi.h"
    266 #include <stdio.h>
    267 #include <math.h>
    268 
    269 int main( int argc, char *argv[])
    270 {
    271     int done = 0, n, myid, numprocs, i;
    272     double PI25DT = 3.141592653589793238462643;
    273     double mypi, pi, h, sum, x;
    274     double startwtime = 0.0, endwtime;
    275     int  namelen;
    276     char processor_name[MPI_MAX_PROCESSOR_NAME];
    277 
    278     MPI_Init(&argc,&argv);
    279     MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
    280     MPI_Comm_rank(MPI_COMM_WORLD,&myid);
    281     MPI_Get_processor_name(processor_name,&namelen);
    282 
    283     printf("Process %d on %s\n", myid, processor_name);
    284 
    285     n = atoll(args[1]);
    286 
    287     startwtime = MPI_Wtime();
    288 
    289     h   = 1.0 / (double) n;
    290     sum = 0.0;
    291     for (i = myid + 1; i <= n; i += numprocs)
    292     {
    293         x = h * ((double)i - 0.5);
    294         sum += 4.0 / (1.0 + x*x);
    295     }
    296     mypi = h * sum;
    297 
    298     MPI_Reduce(&mypi, &pi, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
    299 
    300     if (myid == 0)
    301     {
    302         printf("pi is approximately %.16f, Error is %.16f\n",
    303                pi, fabs(pi - PI25DT));
    304         endwtime = MPI_Wtime();
    305         printf("wall clock time = %f\n", endwtime-startwtime);
    306     }
    307 
    308     MPI_Finalize();
    309 
    310     return 0;
    311 }
    312 }}}
     263
    313264
    314265* DRM4G job template :
    315266{{{
    316267EXECUTABLE    = mpi.sh
    317 ARGUMENTS     = 100000000
    318268STDOUT_FILE   = stdout.${JOB_ID}
    319269STDERR_FILE   = stderr.${JOB_ID}
    320 INPUT_FILES   = mpi.sh, mpi.c
     270INPUT_FILES   = mpi.sh, pi_parallel.c
    321271NP            = 2
    322272}}}
     
    325275{{{
    326276#!sh
    327 mpicc mpi.c -o mpi
    328 chmod +x mpi
    329 mpirun -np 2 ./mpi
    330 }}}
     277source /software/meteo/use/load_use
     278use openmpi14intel
     279chmod +x pi_parallel
     280mpirun -np 2 ./pi_parallel
     281}}}