User Tools

Site Tools


guide:compiling

Compiling

Compilers

The following is a list of C, C++ and Fortran compilers available on the SUN cluster and the M9000:

Intel

  • icc (for C and C++)
  • ifort

GNU

  • gcc
  • g++
  • gfortran

Sun Studio

  • cc
  • CC
  • f90/f95

Environment

module Command

The module command provides a convenient mechanism for managing which environment variables are set in your shell session. The following is a list of the basic usage of the module command:

  • Check which modules are available
    module avail
  • Add a module to the current environment
    module add <module>
  • Show loaded modules
    module list
  • Remove a module from the environment
    module remove <module>

    or

    module rm <module>

To execute multiple module commands from a file (eg. a shell script), create a shell script, e.g.:

#!/bin/bash -l

module load dell/moab_7.1.3_batch
module load dell/torque/4.2.2_batch

module list

This script has to be loaded via the “source” command:

source module_loader.sh

Compiling

Example Code

C

#include <stdio.h>
 
int main()
{
    printf("Hello World");
    return 0;
}

C with MPI

#include <stdlib.h>
#include <stdio.h>
#include <mpi.h>
 
int
main(argc, argv)
 
int                     argc;
char                    *argv[];
 
{
        int             rank, size, len;
        char            name[MPI_MAX_PROCESSOR_NAME];
 
        MPI_Init(&argc, &argv);
        MPI_Comm_rank(MPI_COMM_WORLD, &rank);
        MPI_Comm_size(MPI_COMM_WORLD, &size);
 
        MPI_Get_processor_name(name, &len);
        printf ("Hello world! I'm %d of %d on %s\n", rank, size, name);
 
        MPI_Finalize();
        exit(0);
}

Fortran

PROGRAM Hello
    PRINT *, "Hello World"
END PROGRAM Hello

GNU

The following code snippets demonstrate how to compile the above code examples use the GNU compiler suite:

C

gcc -o hello hello.c

C with MPI

mpicc -o hello hello.c

Fortran

gfortran -o hello hello.f90

Sun Studio

The following code snippets demonstrate how to compile the above code examples use the Sun Studio compiler suite:

C

cc -fast -o hello hello.c

Fortran

f90 -fast -o hello hello.f90

OpenMP

The above compilers include support for OpenMP. To compile an OpenMP code add the -fopenmp option. For example:

gcc -o mp_hello -fopenmp mp_hello.c

code from https://computing.llnl.gov/tutorials/openMP/samples/C/omp_hello.c

Intel Compilers

The following code snippets demonstrate how to compile OpenMP examples with the Intel compilers:

C

icc -openmp omp_hello.c -o hello

Fortran

ifort -openmp omp_hello.f -o hello

MPI

MPI (Message Passing Interface – http://www.open-mpi.org) is provided using the OpenMPI libraries. To compile MPI code use the mpicc or mpif90 compilers.

To run an MPI job see the man pages for PBS Pro. On the login node, type “man qsub”. To obtain an interactive node, use qsub -I The login node prevents long-running processes therefore an interactive node is useful for compilations and builds. To test your code, load the module you want to use first, and then compile your code with it:

$mpicc -o bin/test src/hello_world.c

To test it:

mpirun -np 8 bin/test

You should see something similar to:

Hello world! I'm 7 of 8 on cnode-2-6
Hello world! I'm 6 of 8 on cnode-2-6
Hello world! I'm 5 of 8 on cnode-2-6
Hello world! I'm 1 of 8 on cnode-2-6
Hello world! I'm 0 of 8 on cnode-2-6
Hello world! I'm 3 of 8 on cnode-2-6
Hello world! I'm 2 of 8 on cnode-2-6
Hello world! I'm 4 of 8 on cnode-2-6
/var/www/wiki/data/pages/guide/compiling.txt · Last modified: 2014/02/10 18:07 by ischeepers