Skip to content

Commit

Permalink
Supports building mapping files with multiple MPI tasks
Browse files Browse the repository at this point in the history
For now, this only works on systems with mpirun (not srun, etc.)
  • Loading branch information
xylar committed Oct 16, 2019
1 parent f96b6cf commit fdaf294
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pyremap/remapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ def __init__(self, sourceDescriptor, destinationDescriptor,

# }}}

def build_mapping_file(self, method='bilinear',
additionalArgs=None, logger=None): # {{{
def build_mapping_file(self, method='bilinear', additionalArgs=None,
logger=None, mpiTasks=1): # {{{
'''
Given a source file defining either an MPAS mesh or a lat-lon grid and
a destination file or set of arrays defining a lat-lon grid, constructs
Expand All @@ -117,6 +117,10 @@ def build_mapping_file(self, method='bilinear',
logger : ``logging.Logger``, optional
A logger to which ncclimo output should be redirected
mpiTasks : int, optional
The number of MPI tasks (a number > 1 implies that
ESMF_RegridWeightGen will be called with ``mpirun``)
Raises
------
OSError
Expand All @@ -141,7 +145,9 @@ def build_mapping_file(self, method='bilinear',
# a valid weight file already exists, so nothing to do
return

if find_executable('ESMF_RegridWeightGen') is None:
rwgPath = find_executable('ESMF_RegridWeightGen')

if rwgPath is None:
raise OSError('ESMF_RegridWeightGen not found. Make sure esmf '
'package is installed via\n'
'latest nco: \n'
Expand All @@ -153,14 +159,17 @@ def build_mapping_file(self, method='bilinear',
self.sourceDescriptor.to_scrip(_get_temp_path())
self.destinationDescriptor.to_scrip(_get_temp_path())

args = ['ESMF_RegridWeightGen',
args = [rwgPath,
'--source', self.sourceDescriptor.scripFileName,
'--destination', self.destinationDescriptor.scripFileName,
'--weight', self.mappingFileName,
'--method', method,
'--netcdf4',
'--no_log']

if mpiTasks > 1:
args = ['mpirun', '-np', '{}'.format(mpiTasks)] + args

if self.sourceDescriptor.regional:
args.append('--src_regional')

Expand Down

0 comments on commit fdaf294

Please sign in to comment.