Cbb/Baobab/examples: Difference between revisions
Jump to navigation
Jump to search
Created page with "Hello example mpi program: <PRE> </PRE> <HR> How to compile: First: Setup your environment to use mpi <PRE> module add openmpi-x86_64 </PRE> I generally recommend you add th..." |
No edit summary |
||
| Line 1: | Line 1: | ||
Hello example mpi program: | Hello example mpi program: | ||
<PRE> | <PRE> | ||
/****************************************************************************** | |||
* * 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(); | |||
} | |||
</PRE> | </PRE> | ||
Revision as of 13:47, 6 November 2014
Hello example mpi program:
/******************************************************************************
* * 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