def smart_read_json(mpi_mode, json_file):
"""
read json file under mpi and multi-processing environment
"""
if not mpi_mode:
json_obj = read_json_file(json_file)
else:
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
if rank == 0:
json_obj = read_json_file(json_file)
else:
json_obj = None
json_obj = comm.bcast(json_obj, root=0)
return json_obj
评论列表
文章目录