Here is the Hello World Sample.
Compile it using
Execute it using
Here is the Hello World Sample for Python. You cannot execute it in CC server but you can install the mpi4py module on your workstation
Execute it using
Lecture
MPI Hello World - 2
MPI Pi Calculation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include "mpi.h" | |
int main (int argc, char *argv[]) | |
{ | |
int rank, nprocs; | |
MPI_Init (&argc, &argv); | |
/* creates MPI execution environment */ | |
MPI_Comm_rank (MPI_COMM_WORLD, &rank); | |
/* get current process rank */ | |
MPI_Comm_size (MPI_COMM_WORLD, &nprocs); | |
/* get number of processes */ | |
printf("Hello world from process %d of %d\n", rank, nprocs); | |
MPI_Finalize(); | |
/* terminates the MPI execution environment */ | |
} |
Compile it using
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mpicc helloworld.c |
Execute it using
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mpirun -np 5 ./a.out |
Here is the Hello World Sample for Python. You cannot execute it in CC server but you can install the mpi4py module on your workstation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from mpi4py import MPI | |
comm = MPI.COMM_WORLD | |
print "Hello! I'm rank %d from %d running in total..." % (comm.rank, comm.size) | |
comm.Barrier() | |
#Waits for all process to synchronize _here_ | |
#It is optional as it just allows Hello World to be printed in order 0 ... n-1 |
Execute it using
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mpirun -np 4 helloworld_with_barrier.py |
Lecture
MPI Hello World - 2
MPI Pi Calculation