How to run a python code with mpirun
To test this example start a job with 2 nodes, see Fig. 1
Fig. 1.
Note: Carme uses carme_mpirun
instead of mpirun
. The former adds additional flags to the mpirun command.
-
As an example, create a cpp file:
cd /home/<username> && touch hello_world.cpp
-
Copy the following code to the file:
#include <stdio.h> #include <mpi.h> int main(int argc, char** argv){ int process_Rank, size_Of_Cluster; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &size_Of_Cluster); MPI_Comm_rank(MPI_COMM_WORLD, &process_Rank); printf("Hello World from process %d of %d\n", process_Rank, size_Of_Cluster); MPI_Finalize(); return 0; }
-
Compile your file:
mpic++ hello_world.cpp -o hello_world.exe
-
Run your executable file:
carme_mpirun -np 2 ./hello_world.exe
-
The output shows that two processors were used:
Hello, World from process 0 of 2. Hello, World from process 1 of 2.