Skip to content

Commit 548adc2

Browse files
committed
Removing MPI initialization from module testing
1 parent c854f69 commit 548adc2

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

rsopt/util.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,14 @@ def return_nodelist(nodelist_string):
5555
def return_used_nodes():
5656
"""Returns all used processor names to rank 0 or an empty list if MPI not used. For ranks != 0 returns None."""
5757
try:
58-
from mpi4py import MPI
58+
import mpi4py
59+
mpi4py.rc.initialize = False
5960
except ModuleNotFoundError:
6061
# If MPI not being used to start rsopt then no nodes will have srun executed yet
6162
return []
6263

64+
from mpi4py import MPI
65+
MPI.Init()
6366
rank = MPI.COMM_WORLD.Get_rank()
6467
name = MPI.Get_processor_name()
6568
all_names = MPI.COMM_WORLD.gather(name, root=0)
@@ -93,11 +96,14 @@ def return_unused_node():
9396
def broadcast(data, root_rank=0):
9497
"""broadcast, or don't bother"""
9598
try:
96-
from mpi4py import MPI
99+
import mpi4py
100+
mpi4py.rc.initialize = False
97101
except ModuleNotFoundError:
98102
# If MPI not available for import then assume it isn't needed
99103
return data
100104

105+
from mpi4py import MPI
106+
MPI.Init()
101107
if MPI.COMM_WORLD.Get_size() == 1:
102108
return data
103109

@@ -121,4 +127,4 @@ def _libe_save(H, persis_info, mess, filename):
121127
np.save(filename, H)
122128

123129
with open(filename + ".pickle", "wb") as f:
124-
pickle.dump(persis_info, f)
130+
pickle.dump(persis_info, f)

0 commit comments

Comments
 (0)