U  g@sddlZddlZddlZddlZddlZddlZddlmZm Z ej j dddZ e dZddd Zd d Zd d ZddZddZddZdddZdS)N)CMDFGenMPIMixed mpiexec_mptF) 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 syncpversionstatusrJ/lfs/h1/ops/prod/packages/hmon.v3.2.7/ush/produtil/mpi_impl/mpiexec_mpt.pyrunsyncs rcCs<|dk r0t|dr||_t|dr8|j|dSn|`|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 integerNthreadsenv)OMP_NUM_THREADS)hasattrrr)argrrrropenmp!s  rcCstdk S)zE!Detects whether the SGI MPT is available by looking for mpiexec_mpt.N)mpiexec_mpt_pathrrrrdetect1sr cCs`ttjdd}ttjdd}|dkr8|dkr8|S|dkrDdn|}|dkrTdn|}||S)zp!Tries to guess the number of threads in use @param default the value to return if the function cannot guessrNMKL_NUM_THREADSr)intosenvironget)defaultZompZmklrrrguess_nthreads5sr'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_bigexeDsr-c KsXt|tjjst|\}}|r.|r.td|dkrt|rtdd|jt gdt j dgdgdD}tj |}n|rtd n|rtj|}d d|jd d d D}tjd dkrtdtj j t dd|d gtd|f|d}n6dd|jt gddgdgdD}tj |jdd}|jdddd}|jrTd|j}|j|dd|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 program @warning Assumes the TOTAL_TASKS environment variable is set if allranks=TruezACannot mix serial and parallel MPI ranks in the same MPI program.rcSsg|]}|qSrr.0arrr Zszmpirunner..z-n TOTAL_TASKS:)prebeforebetweenzWhen using allranks=True, you must provide an mpi program specification with only one MPI rank (to be duplicated across all ranks).cSsg|]}|qSrrr.rrrr1csT)to_shellexpand mpiserialNzbAttempting to run a serial program via mpiexec_mpt but the mpiserial program is not in your $PATH.z%s serialcmdf)preruncSsg|]}|qSrrr.rrrr1jsz%(n)d)MPI_TYPE_DEPTHi)r=ZMPI_BUFS_PER_PROCZMPI_BUFS_PER_HOSTz%d1)rr!) isinstancer mpiprog MPIRanksBaseAssertionError check_serialrnranks to_arglistrr#r$r r MPIAllRanksErrorcollapsefileopfind_exeMPISerialMissingrrr) rallranksr,serialparallelarglistrunnerlinessrrr mpirunnerKsB           rS)N)F)r#loggingprodutil.fileopr produtil.progprodutil.mpiprogprodutil.pipeline mpi_impl_baserrrIrJr getLoggerr rrr r'r(r-rSrrrrs