fortran - Does a program started with mpiexec know it was started with mpiexec? -
i'm in process of adding option fortran program run using multiple processors using mpi. if user going run in parallel, user needs specify different input files---one file each domain (processor) of problem. program specific filename default (a file called "serial.inp"). need program know when being run in parallel can instead other filenames instead (e.g. "parallel_1.inp", "parallel_2.inp", "parallel_3.inp", etc.). first thought have user pass argument program when execute it, e.g.:
mpiexec -n 4 myprogram.exe -parallel
this way, parallel files when argument present. seems kind of redundant. if program being called mpiexec, there no question user attempting run in parallel. there way program know started using mpiexec? or command line argument best bet?
alex leach right in can mpi-implementation-specific environment variable lookups, there's no portable way this.
but understand, don't think need to; can of want checking see if run 1 rank:
program filenames use mpi implicit none integer :: comsize, rank, ierr character(len=128) :: inputfilename call mpi_init(ierr) call mpi_comm_size(mpi_comm_world,comsize,ierr) call mpi_comm_rank(mpi_comm_world,rank,ierr) if (comsize == 1) inputfilename = 'serial.inp' else write(inputfilename, '(a,i0,a)'), 'parallel_',rank,'.imp' endif write(*,'(i,1x,a)'), rank, trim(inputfilename) call mpi_finalize(ierr) end program filenames
running gives
$ mpirun -np 4 ./filenames 0 parallel_0.imp 1 parallel_1.imp 2 parallel_2.imp 3 parallel_3.imp $ ./filenames 0 serial.inp
that's not perfect; it'll give serial result if run using mpirun -np 1 filenames
, depending on use case may not terrible thing in exchange having portable.
Comments
Post a Comment