Last active
June 3, 2022 09:38
-
-
Save serihiro/33f8f775cd8ba524d7b20d08d170e69c to your computer and use it in GitHub Desktop.
Get MPI rank in the executing shell script
This file contains hidden or 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 | |
rank=`python get_mpi_rank.py` | |
if [ ${rank} -eq 0 ]; then | |
echo 'I am rank 0' | |
elif [ ${rank} -eq 1 ]; then | |
echo 'I am rank 1' | |
elif [ ${rank} -eq 2 ]; then | |
echo 'I am rank 2' | |
elif [ ${rank} -eq 3 ]; then | |
echo 'I am rank 3' | |
fi | |
# $ mpirun -np 4 executable.sh | |
# I am rank 1 | |
# I am rank 3 | |
# I am rank 2 | |
# I am rank 0 |
This file contains hidden or 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 | |
comm = MPI.COMM_WORLD | |
print(comm.Get_rank()) |
Thank you so much. Before I saw your code, I have no idea how to get the current rank of the bash script. Now I know I need to run a program inside the bash script to find its rank.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the file name should be get_mpi_rank not get_my_rank