def spawn_load(self):
'''spwan a parallel loading process using MPI'''
if not para_load:
return
from mpi4py import MPI
import os
import sys
hostname = MPI.Get_processor_name()
mpiinfo = MPI.Info.Create()
# will give all nodes filled issue if use key=host because need an additional slot
# also the hostname should be exactly the same in the output list of --display-allocation
if hostname != hostname.split('.')[0]:
hostname = hostname.split('.')[0]
mpiinfo.Set(key = 'add-host',value = hostname)
num_spawn = 1
if "CPULIST_train" in os.environ:
# see https://gist.github.com/lebedov/eadce02a320d10f0e81c
# print os.environ['CPULIST_train']
envstr=""
# for key, value in dict(os.environ).iteritems():
# envstr+= '%s=%s\n' % (key,value)
envstr+='CPULIST_train=%s\n' % os.environ['CPULIST_train']
mpiinfo.Set(key ='env', value = envstr)
ninfo = mpiinfo.Get_nkeys()
# print ninfo
mpicommand = sys.executable
file_dir = os.path.dirname(os.path.realpath(__file__))# get the dir of imagenet.py
self.icomm= MPI.COMM_SELF.Spawn(mpicommand,
args=[file_dir+'/proc_load_mpi.py'],
info = mpiinfo, maxprocs = num_spawn)
评论列表
文章目录