U  g@sddlZddlZddlZddlZddlZddlZddlmZm Z ej j dddZ e dZddd Zd d Zd d ZddZddZdddZdddZdS)N)MPIMixedCMDFGensrunF) raise_missinglsf_cray_intelcCs@|dkr t}tjdg}tjj|d|d}|}|}dS)z%!Runs the "sync" command as an exe().Nz /bin/syncT)capturelogger) module_loggerprodutilprogRunnerpipelinePipeline to_stringpoll)r syncpversionstatusrC/lfs/h1/ops/prod/packages/hmon.v3.2.7/ush/produtil/mpi_impl/srun.pyrunsyncs rcCs6|dk s t|dk r*||_|j||ddS|`|SdS)z!Adds OpenMP support to the provided object @param arg An produtil.prog.Runner or produtil.mpiprog.MPIRanksBase object tree @param threads the number of threads, or threads per rank, an integerNscatter)OMP_NUM_THREADSKMP_NUM_THREADS KMP_AFFINITY)AssertionErrorthreadsenv)argrrrropenmps r!cCstdk S)zX!Detects whether the SLURM srun command is available by looking for it in the $PATH.N) srun_pathrrrrdetect*sr#cCsdS)z@!Does this module represent an MPI implementation? Returns True.Trrrrr can_run_mpi/sr$cKstjjt|gf|S)z!Returns an ImmutableRunner that will run the specified program. @returns an empty list @param exe The executable to run on compute nodes. @param kwargs Ignored.)r r ImmutableRunnerstr)exekwargsrrr make_bigexe3sr)cKs8t|fd|i|}tddt|t|f|S)a!Turns a produtil.mpiprog.MPIRanksBase tree into a produtil.prog.Runner @param arg a tree of produtil.mpiprog.MPIRanksBase objects @param allranks if True, and only one rank is requested by arg, then all MPI ranks will be used @param kwargs passed to produtil.mpi_impl.mpi_impl_base.CMDFGen when mpiserial is in use. @returns a produtil.prog.Runner that will run the selected MPI programallranksrz%s => %s)mpirunner_impllogging getLoggerinforepr)r r*r(frrr mpirunner:s r1c Ksdt|tjjst|\}}|r.|r.tdtdddg}|dkrp|rpdd|j |ggdD}tj |S|r~t d n|rtj |}d d|j d d d D}tjd dkrtdtj j tdd|d gtd|f|dSt}d} |jddD]2\} } |d| | | d| f| | 7} qtj j tdt| dgtd|fdd i|dSdS)zZ!This is the underlying implementation of mpirunner and should not be called directly.zACannot mix serial and parallel MPI ranks in the same MPI program.z --export=ALLz--cpu_bind=corez--distribution=block:blockrcSsg|] }t|qSrr&.0arrr Rsz"mpirunner_impl..)prebeforebetweenzWhen using allranks=True, you must provide an mpi program specification with only one MPI rank (to be duplicated across all ranks).cSsg|] }t|qSrr2r3rrrr6\sT)to_shellexpand mpiserialNz[Attempting to run a serial program via srun but the mpiserial program is not in your $PATH.z-nz%s serialcmdf)prerunrF)r;z%d-%d %sz --multi-progZ srun_cmdfile filename_arg) isinstancer mpiprog MPIRanksBaser check_serialrr"nranks to_arglistr r MPIAllRanksErrorcollapsefileopfind_exeMPISerialMissingrlist expand_iterappendr:r&) r r*r(serialparallelZ srun_argsarglistlinesZcmdfileZirankrankcountrrrr+FsH         r+)N)F)F)osr,produtil.fileopr produtil.progprodutil.mpiprogprodutil.pipeline mpi_impl_baserrrHrIr"r-r rr!r#r$r)r1r+rrrr s