<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import os <EOL> from six import itervalues <EOL> from openmdao . core . group import Group <EOL> from openmdao . util . array_util import evenly_distrib_idxs <EOL> from openmdao . core . mpi_wrap import MPI <EOL> trace = os . environ . get ( '<STR_LIT>' ) <EOL> if trace : <EOL> from openmdao . core . mpi_wrap import debug <EOL> class ParallelFDGroup ( Group ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , num_par_fds ) : <EOL> super ( ParallelFDGroup , self ) . __init__ ( ) <EOL> self . fd_options [ '<STR_LIT>' ] = True <EOL> self . _num_par_fds = num_par_fds <EOL> self . _par_fd_id = <NUM_LIT:0> <EOL> def _setup_communicators ( self , comm , parent_dir ) : <EOL> """<STR_LIT>""" <EOL> if self . _num_par_fds < <NUM_LIT:1> : <EOL> raise ValueError ( "<STR_LIT>" % <EOL> ( self . pathname , self . _num_par_fds ) ) <EOL> if not MPI : <EOL> self . _num_par_fds = <NUM_LIT:1> <EOL> self . _full_comm = comm <EOL> if self . _num_par_fds > <NUM_LIT:1> : <EOL> minprocs , maxprocs = super ( ParallelFDGroup , self ) . get_req_procs ( ) <EOL> sizes , offsets = evenly_distrib_idxs ( self . _num_par_fds , comm . size ) <EOL> color = [ ] <EOL> for i in range ( self . _num_par_fds ) : <EOL> color . extend ( [ i ] * sizes [ i ] ) <EOL> self . _par_fd_id = color [ comm . rank ] <EOL> if trace : <EOL> debug ( '<STR_LIT>' % ( self . pathname , <EOL> self . _par_fd_id ) ) <EOL> comm = comm . Split ( self . _par_fd_id ) <EOL> self . _local_subsystems = [ ] <EOL> self . comm = comm <EOL> self . _setup_dir ( parent_dir ) <EOL> for sub in itervalues ( self . _subsystems ) : <EOL> sub . _setup_communicators ( comm , self . _sysdata . absdir ) <EOL> if self . is_active ( ) and sub . is_active ( ) : <EOL> self . _local_subsystems . append ( sub ) <EOL> def get_req_procs ( self ) : <EOL> """<STR_LIT>""" <EOL> minprocs , maxprocs = super ( ParallelFDGroup , self ) . get_req_procs ( ) <EOL> minprocs *= self . _num_par_fds <EOL> if maxprocs is not None : <EOL> maxprocs *= self . _num_par_fds <EOL> return ( minprocs , maxprocs ) </s>
