-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to mpi4py.futures, simplify bash script
Migrate the Python script from mpi4py.MPI to mpi4py.futures. Note that mpi4py.futures requires a separate launcher script to create the MPI environment and launch the main script. When using mpi4py.futures, the MPIPoolExecutor needs to be started in a separate process. This is because the MPIPoolExecutor must be created and submitted to tasks within an if __name__ == '__main__': block to prevent recursive creation of MPIPoolExecutor instances. Also, in the bash commands: - Modify the bash code to remove or clear the python-test directory, if it already exists. This ensures a clean environment for every test run. - Simplify the scp file transfer code, to one line.
- Loading branch information
Showing
4 changed files
with
45 additions
and
33 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,32 @@ | ||
## Login | ||
# Login (CMD) | ||
ssh -J [email protected] [email protected] | ||
|
||
## Make new directory | ||
mkdir python-test | ||
# Move to scratch folder | ||
cd ../../scratch/eterhoeven | ||
|
||
# Check if directory exists | ||
if [ -d "python-test" ]; then | ||
# Remove all files and subdirectories inside the directory | ||
rm -r python-test/* | ||
else | ||
# Create new directory | ||
mkdir python-test | ||
fi | ||
|
||
# Change to the python-test directory | ||
cd python-test | ||
|
||
## Move files | ||
cd C:\Users\Ewout\OneDrive\Studie\CapitaSelecta\ | ||
scp -J [email protected] my_model.py [email protected]:/scratch/eterhoeven/python-test | ||
scp -J [email protected] test_script.sh [email protected]:/scratch/eterhoeven/python-test | ||
# Move files (NEW CMD) | ||
cd C:\Users\Ewout\Documents\GitHub\EMAworkbench\scripts | ||
scp -J [email protected] my_model.py launcher.py test_script.sh [email protected]:/scratch/eterhoeven/python-test | ||
|
||
# Check if files are correctly tranfered | ||
ls | ||
|
||
# Note: bash scripts (sh) needs LF line endings. Do that in atom. | ||
|
||
## Note: bash scripts (sh) needs LF line endings. Do that in atom. | ||
# Run batch script | ||
sbatch test_script.sh | ||
|
||
## Run batch script | ||
sbatch test_script.sh | ||
# Check queue | ||
squeue -u eterhoeven |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# launcher.py | ||
from mpi4py.futures import MPIPoolExecutor | ||
import my_model | ||
|
||
if __name__ == '__main__': | ||
with MPIPoolExecutor() as executor: | ||
executor.submit(my_model) |
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
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