python - os.chdir() doesn't work with mpi4py spawning -


i have small test code acts task farm. idea list of tasks sent group of processes spawned mpi4py, in turn change run directory , spawn mpi-executable in directory before returning, , retrieving new task.

the problem execution of mpi-executable seems happen in top level directory original program has been run.

the master code executed in /top/level/folder/

and contains list of tasks, e.g: [0,1,2,3,4,5,6,7,8,9,10]. slaves each receive task , change directory of same name, before executing mpi-executable, , changing back.

the master code:

#!/usr/bin/env python mpi4py import mpi import numpy np import sys import os import time   comm = mpi.comm_world rank = mpi.comm_world.get_rank()  processes=4  tasks=([stopiteration] * (processes))+[0,1,2,3,4,5,6,7,8,9,10]  new_comm=comm.spawn("/path/to/slave/slave.py",                   args=[],maxprocs=processes)  status=mpi.status()  while tasks:     new_comm.recv(source=mpi.any_source, status=status)     data=tasks.pop()     print("on master received source: ",status.get_source())     print("on master sending: ",data," to:",status.get_source())     new_comm.send(obj=data,dest=status.get_source())     print("on master sent: ",data," to:",status.get_source())   print("finished all",rank) new_comm.barrier() print("after barrier",rank) print("rank", rank,"task",tasks) new_comm.disconnect() 

and slave.py code:

#!/usr/bin/env python mpi4py import mpi import numpy np import sys import os import time  comm = mpi.comm.get_parent() rank = comm.get_rank() cwd=os.getcwd()  print("slave", rank," entering loop") task in iter(lambda: comm.sendrecv(dest=0), stopiteration):     print("slave ", rank," recvd data", task)     print("slave ", rank," going sleep")     directory=os.path.join(cwd,str(task))     os.chdir(directory)     new_comm=mpi.comm_self.spawn("/path/to/some/mpi-executable",                   args=[],maxprocs=4)     os.chdir(cwd)     new_comm.barrier()     new_comm.free()   comm.barrier() comm.disconnect() 

but each instance of mpi-executable trying launch in /top/level/folder/

any ideas why behaviour happening appreciated!

mpi_comm_spawn, mpi operation mpi.comm.spawn built on, takes mpi_info object can used supply additional implementation-specific information. argument can supplied in mpi4py named info argument.

info = mpi.info.create() info.set('key', 'value') mpi.comm.spawn(..., info=info, ...) 

with many of existing mpi implementations info key setting working directory of child processes wdir.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -