Logo Cineca Logo SCAI
MARCONI status
GALILEO100 status
Marconi100 status

You are here

Computing PI - Native mode (MPI)

Here you'll find simple programs for computing the value of PI using MPI .

 

First you have to load the correct compiler, the mpi library, fix the environment and enable MPI for MIC

module load intel (i.e. compiler suite)
module load intelmpi (i.e. mpi library)
source $INTEL_HOME/bin/compilervars.sh intel64 (to set up the environment variables)
export I_MPI_MIC=enable (to enable mpi on MIC)

 

Now you can cross-compile the code for running on the MIC coprocessor using mpicc for C programs and mpifc for fortran ones

C: mpicc pi_mpi.c -mmic -o pi_mpi_C.x
Fortran: mpifc pi_mpi.F90 -mmic -o pi_mpi_F.x

 

Now you can run you job without entering the MIC coprocessor, but defining the MIC you are intended to run on, using the command mpirun.

mpirun.mic  -host node021-mic0 -np 20  ./pi_mpi_C.x
MPI version with tasks = 20
Number of intervals: 10000000
Computed PI 3.141592653589793560087173
The true PI 3.141592653589793115997963
Error -0.000000000000000444089210

Elapsed time (s) = 0.007134
....
mpirun.mic -host node021-mic0 -np 40 ./pi_mpi_C.x
MPI version with tasks = 40
Number of intervals: 10000000
Computed PI 3.141592653589793115997963
The true PI 3.141592653589793115997963
Error 0.000000000000000000000000

Elapsed time (s) = 0.005281

 

mpirun.mic -host node021-mic0 -np 50 ./pi_mpi_F.x 
MPI version with tastks = 50
Number of intervals = 10000000
Computed PI 3.1415926535897935600871733
The True PI 3.1415926535897931159979635
Error -0.0000000000000004440892099

Elapsed time 3.990888595581055E-003 s
...
mpirun.mic -host node021-mic0 -np 5 ./pi_mpi_F.x
MPI version with tastks = 5
Number of intervals = 10000000
Computed PI 3.1415926535897904514627044
The True PI 3.1415926535897931159979635
Error 0.0000000000000026645352591

Elapsed time 2.462911605834961E-002 s