Skip to content

Instantly share code, notes, and snippets.

@victorskl
Last active March 28, 2019 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorskl/aaed38985e72d9b87460c1bb52820c60 to your computer and use it in GitHub Desktop.
Save victorskl/aaed38985e72d9b87460c1bb52820c60 to your computer and use it in GitHub Desktop.
MPI Hello World
// Hello World MPI C program from Lecture 3, slide 31
#include <stdio.h>
#include <mpi.h>
int main(argc, argv)
int argc;
char *argv[];
{
int rank, size;
MPI_Init(&argc, &argv); // starts MPI
MPI_Comm_rank(MPI_COMM_WORLD, &rank); // get current process id
MPI_Comm_size(MPI_COMM_WORLD, &size); // get number of processes
printf("Hello world from process %d of %d\n", rank, size);
MPI_Finalize();
return 0;
}
// To compile
//module load OpenMPI/1.10.0-GCC-4.9.2
//mpicc -o hello hello.c
// To run (see jobc.sh)
//module load OpenMPI/1.10.0-GCC-4.9.2
//mpirun hello
from mpi4py import MPI
size = MPI.COMM_WORLD.Get_size()
rank = MPI.COMM_WORLD.Get_rank()
print("Hello World! I am process %d of %d.\n" % (rank, size))
#!/bin/bash
#SBATCH --account=comp90024
#SBATCH --job-name=HelloJob
#SBATCH -p cloud
#SBATCH --time=00:01:00
#SBATCH --nodes=1
#SBATCH --ntasks=8
#SBATCH --cpus-per-task=1
echo 'HelloJob'
echo ' '
module load Python/3.6.4-intel-2017.u2
echo 'Python Path: '
which python
echo ' '
mpirun python hello.py
#!/bin/bash
#SBATCH --account=comp90024
#SBATCH --job-name=HelloJobC
#SBATCH -p cloud
#SBATCH --time=00:01:00
#SBATCH --nodes=1
#SBATCH --ntasks=8
#SBATCH --cpus-per-task=1
echo 'HelloJobC'
echo ' '
# This job script is for hello.c program.
# You should compile it first, see hello.c note.
module load OpenMPI/1.10.0-GCC-4.9.2
mpirun hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment