UC San Diego SearchMenu

Compiling Parallel Codes

The default compiler/mpi stack combination is the Intel compiler (ifort, icc) and openmpi_ib. Other compilers and mpi variants may be accessed by loading the appropriate modules. The commands mpicc, mpiCC, mpif77, mpif90 will access a particular compiler/mpi combination based on the module choices. Read about modules to learn how TSCC manages compiler configurations.

A simple MPI C program is given below (mpi_c.c):

C Example

  • mpicc -o mpi_c mpic.c
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
main(int argc,char *argv[])
{
   int myproc,numproc;
   MPI_Status status;

   MPI_Init(&argc,&argv);

   MPI_Comm_rank(MPI_COMM_WORLD,&myproc);
   MPI_Comm_size(MPI_COMM_WORLD,&numproc);

   if(myproc == 0)
        printf("NUMPROC %d\n",numproc);
   printf("Process %d\n running",myproc);
   MPI_Finalize();
}

This program can be compiled with the following command

mpicc -o mpi_c mpic.c

The program will print the total number of MPI processes initiated and a message printed by each process (see Submitting a Job)

Fortran Example

  • mpif77 -o mpi_f mpi_f.f

Following is the Fortran equivalent of the above program (mpi_f.f):

program mpi
implicit double precision (a-h,o-z)
include "mpif.h"

call mpi_init(ierror)

call mpi_comm_rank(MPI_COMM_WORLD,myproc,ierror)
call mpi_comm_size(MPI_COMM_WORLD,numproc,ierror)
if(myproc.eq.0) write(6,*) 'NUMPROC ',numproc
write(6,*) 'Process ',myproc,' running'
call mpi_finalize();
end

and can be compiled as follows :

mpif77 -o mpi_f mpi_f.f

More information about compiling can be found on the Compiling Jobs page.