Logo Cineca Logo SCAI
MARCONI status
GALILEO100 status
Marconi100 status

You are here

Computing PI - Native mode (OpenMP)

 

Here you'll find a simple program to compute pi value using OpenMP directives.

 

First you have to load the correct compiler and fix the environment

module load intel (i.e. compiler suite)
source $INTEL_HOME/bin/compilervars.sh intel64 (to set up the environment variables)

 

Now you can cross-compile the code for running on the MIC coprocessor:

C: icc pi.c -openmp -mmic -o pi_C.x
Fortran: ifort pi.F90 -openmp -mmic -o pi_F.x

 

Now you have to enter, via ssh (see here) directly to the MIC reserved for you, and there you have to setup environment variables

export LD_LIBRARY_PATH=/cineca/prod/compilers/intel/cs-xe-2013/binary/lib/mic:${LD_LIBRARY_PATH}

 

Finally you can run the programs, setting the number of threads to use

export OMP_NUM_THREADS=4
./pi_C.x
Open-MP version with threads = 4
Number of intervals: 10000000
Computed PI 3.141592653589794004176383
The true PI 3.141592653589793115997963
Error -0.000000000000000888178420

Elapsed time (s) = 0.071319

 

export OMP_NUM_THREADS=30
./pi_F.x
Open-MP version with threads = 30
Number of intervals: 10000000
Computed PI 3.1415926535897935600871733
The True PI 3.1415926535897931159979635
Error -0.0000000000000004440892099

Elapsed time 4.498958587646484E-003 s

export OMP_NUM_THREADS=3
./pi_F.x
Open-MP version with threads = 3
Number of intervals: 10000000
Computed PI 3.1415926535898015536929506
The True PI 3.1415926535897931159979635
Error -0.0000000000000084376949872

Elapsed time 4.128289222717285E-002 s