Appendko

Python_mpi_rank

Apr 11th, 2021
429
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # run this python script using
  2. # mpirun -np 4 this_script.py
  3. import os
  4.  
  5. # Assuming you need to do 24 jobs, which is labeled as 0, 1, 2 ... 23
  6. job_size = 24
  7.  
  8. # Environment Variable provide by mpirun
  9. worker_size = int(os.environ['OMPI_COMM_WORLD_SIZE'])
  10. worker_id = int(os.environ['OMPI_COMM_WORLD_RANK'])
  11.  
  12. all_jobs = range(24)
  13. job_for_this_worker = [x for x in all_jobs if x % worker_size == worker_id]
  14.  
  15. print("I am worker #%d, I'm going to run "%worker_id, job_for_this_worker)
  16.  
  17. # then start run the code you want
  18. # for x in job_for_this_worker:
  19. #     do_something(x)
  20.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×