Skip to content

Commit 38ca43d

Browse files
committed
Adding same change to mpi.py per request
1 parent 548adc2 commit 38ca43d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

rsopt/mpi.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11

22
def get_mpi_environment():
33
try:
4-
from mpi4py import MPI
4+
import mpi4py
5+
mpi4py.rc.initialize = False
56
except ModuleNotFoundError:
67
# mpi4py not installed so it can't be used
78
return
@@ -11,8 +12,10 @@ def get_mpi_environment():
1112
# (if user did start MPI with size 1 this would be an illegal configuration since: main + 1 worker = 2 ranks)
1213
return
1314

15+
from mpi4py import MPI
16+
MPI.Init()
1417
nworkers = MPI.COMM_WORLD.Get_size() - 1
1518
is_manager = MPI.COMM_WORLD.Get_rank() == 0
1619
mpi_environment = {'mpi_comm': MPI.COMM_WORLD, 'comms': 'mpi', 'nworkers': nworkers, 'is_manager': is_manager}
1720

18-
return mpi_environment
21+
return mpi_environment

0 commit comments

Comments
 (0)