Cbb/Baobab/examples
Hello example mpi program: Save this as hello.c
/****************************************************************************** * * FILE: mpi_hello.c * * DESCRIPTION: * * MPI tutorial example code: Simple hello world program * * AUTHOR: Blaise Barney * * LAST REVISED: 03/05/10 * ******************************************************************************/ #include "mpi.h" #include <stdio.h> #include <stdlib.h> #define MASTER 0 int main (int argc, char *argv[]) { int numtasks, taskid, len; char hostname[MPI_MAX_PROCESSOR_NAME]; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &numtasks); MPI_Comm_rank(MPI_COMM_WORLD,&taskid); MPI_Get_processor_name(hostname, &len); printf ("Hello from task %d on %s!\n", taskid, hostname); if (taskid == MASTER) printf("MASTER: Number of MPI tasks is: %d\n",numtasks); MPI_Finalize(); }
How to compile:
First: Setup your environment to use mpi
module add openmpi-x86_64
I generally recommend you add this to your .bashrc file.
Second: Compile your program
mpicc -o hello hello.c
Third: Edit your submit script to match how you want to run your parallel program.
vi sub_script
Forth: Submit your script into the queue
qsub sub_script