Last active
March 28, 2019 05:39
-
-
Save victorskl/aaed38985e72d9b87460c1bb52820c60 to your computer and use it in GitHub Desktop.
MPI Hello World
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
// 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 |
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
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)) |
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
#!/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 |
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
#!/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