Cbb/Baobab/examples: Difference between revisions

From Computer Science Wiki
Jump to navigation Jump to search
Rhunter (talk | contribs)
No edit summary
Rhunter (talk | contribs)
No edit summary
 
(One intermediate revision by the same user not shown)
Line 34: Line 34:
First: Setup your environment to use mpi
First: Setup your environment to use mpi
<PRE>
<PRE>
module add openmpi-x86_64
module add mpi/openmpi-x86_64
</PRE>
</PRE>
I generally recommend you add this to your .bashrc file.
I generally recommend you add this to your .bashrc file before you get started.
 


Second: Compile your program
Second: Compile your program

Latest revision as of 09:17, 11 August 2015

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 mpi/openmpi-x86_64

I generally recommend you add this to your .bashrc file before you get started.


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