Compiling and Running MPI/C Code on Odyssey
A simple MPI example C code is:
#include <stdio.h>
#include <mpi.h>
#define BUFSIZE 128
main(int argc, char *argv[])
{
char name[BUFSIZ];
int length;
int n;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &n);
if (n==0)
{
length=10.;
}
MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Get_processor_name(name, &length);
MPI_Barrier(MPI_COMM_WORLD);
printf("%s: hello world. n=%dn", name, n);
MPI_Barrier(MPI_COMM_WORLD);
MPI_Finalize();
}
A Makefile to go with this would be:
CC=mpicc
CFLAGS=-O -g
LIBS=-lm
RM=/bin/rm
EXECS = hello
OBJS = hello.o
all: $(EXECS)
$(EXECS): $(OBJS) Makefile
$(CC) $(CFLAGS) -o $(EXECS) $(OBJS) $(LIBS)
$(OBJS): Makefile
.c.o:
$(CC) $(CFLAGS) -o $*.o -c $*.c
clean:
$(RM) -f $(EXECS) $(OBJS) gmon.out *~ *.o *.oo
A LSF submission script to submit this job could be:
#!/bin/sh
#BSUB -u rchelp@fas.harvard.edu
#BSUB -J hello_world
#BSUB -o hello_lsf.out
#BSUB -e hello_lsf.err
#BSUB -n 16
#BSUB -q short_parallel
#BSUB -a openmpi
mpirun.lsf ./hello 1> hello.out 2> hello.err
To debug your MPI code you should use Totalview. Look at our FAQ on debugging parallel code for more information.
For more help…
