1.0-8
Compiling Programs |
![]() ![]() |
Back to Main Documentation Page |
$ gcc -o mm mm.c clock.c fcycmm.c
The program can be run by entering:
$ ./mm
If you wanted to use another compiler, then you can switch compiling environments by using modules. For example, if you wanted to use the Portland Group C Version 6.2 compiler you would enter the following (assuming Portland Group Version 6.2 is installed on your system)
$ module load pgi62 $ pgcc -o mm mm.c clock.c fcycmm.c mm.c: clock.c: fcycmm.c: $ ./mm pgcc -o mm mm.c clock.c fcycmm.c
A Makefile and program files can be found here.
Using Fortran can be done as follows, for the program mm.f, gfortran (or g77) can be used to compile the binary.
$ gfortran -o mm mm.f $ ./mm
If the Portland Group module is still resident, then you can use pgf90:
$ pgf90 -o mm mm.f $ ./mm
A Makefile and program file can be found here.
To remove a module, enter:
module rm pgi62
Modules can be valuable is you have multiple versions of the same compiler. For instance, for historical reasons, if you need to use Portland Group Version 5.2
for some reason, it is simple to change the module (pgi52) and compile your code. Module eliminate excessive editing of login scripts where pathnames to
compilers are often set.
We will use the cpic.c and the fpi.f examples.
First we will need to install the MPICH module by entering:
Building Parallel Programs Using MPI
Suppose you want to compile a program using gcc and mpich.
$module load mpi/mpich-gnu4
$mpicc -o cpi cpi.cIf you enter a which mpicc you will see that it points to the MPICH directory. To run your program, Create/Edit file named "machines" with machine list. You can get a list of available nodes using the wwlist command. For example, your nodes file may look like:
node000 node001 node002 node003Now enter the mpirun command:
$mpirun -np 4 -machinefile machines cpiYou should see output similar to that below:
Process 0 on hydra-ww Process 1 on node000 Process 2 on node001 Process 3 on node002 pi is approximately 3.1415926535902168, Error is 0.0000000000004237 wall clock time = 0.609375The same can be done for Fortran programs.
$mpif77 -o fpi fpi.f $mpirun -np 8 -machinefile machines fpiThe screen should scroll until the following is displayed:
. . . 9998 points: pi is approximately: 3.1415926544234614 error is: 0.0000000008336682 9999 points: pi is approximately: 3.1415926544232922 error is: 0.0000000008334990 10000 points: pi is approximately: 3.1415926544231239 error is: 0.0000000008333307The power of modules is that you can change the module, and run the same tests for other MPIs (The procedure for starting each MPI may vary). The following links provide examples for various installed MPIs.
The following command sequence illustrates the use of these commands:
$ module list Currently Loaded Modulefiles: 1) mpi/mpich-gnu4 $ module avail ------------------------ /usr/share/modules/modulefiles ------------------------ blas-gnu4 lapack-pgi mpi/mpich-pgi pgi52 blas-pgi module-cvs mpi/mpich2-gnu4 pgi62 dot module-info mpi/mpichgm-gnu4 sge fftw2-pgi modules mpi/mpichgm-pgi use.own fftw3-gnu4 mpi/lam-gnu4 mpi/ompi-gnu4 fftw3-pgi mpi/lam-pgi namd-pgi lapack-gnu4 mpi/mpich-gnu4 null $ module rm mpi/mpich-gnu4 $ module load mpi/mpichgm-gnu4 $ module list Currently Loaded Modulefiles: 1) mpi/mpichgm-gnu4 $ module purge $ module list No Modulefiles Currently Loaded.A note about gnu modules: All GNU compiler modules have either a -gnu3 or -gnu4 tag to indicate which major version of the compilers are to be used. In general, RHEL4 and older use GNU 3, while Fedora 4 and above, use GNU 4. You can check your system by entering gcc -v at the command prompt.
MPI and Compilers: In order to ensure interoperability, each MPI module has a compiler associated with it. All clusters support either the -gnu3 or -gnu4 (see above). Check with your system administrator to see what compilers are available on you cluster. modules
This page, and all contents, are Copyright © 2007,2008 by Basement Supercomputing, Bethlehem, PA, USA, All Rights Reserved. This notice must appear on all copies (electronic, paper, or otherwise) of this document.