Skip to content

Commit

Permalink
Add a patch to disable mpi4py with an env. var.
Browse files Browse the repository at this point in the history
This is similar to what was done in the previous merge for the
cdms2 package, but this time for the regrid2 package.
  • Loading branch information
xylar committed Jun 9, 2021
1 parent 994568c commit 2cd25e8
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
67 changes: 67 additions & 0 deletions recipe/0005-env_flag_to_disable_mpi4py_in_regrid2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
diff -ruN cdms-3.1.5/regrid2/Lib/esmf.py cdms-3.1.5-patch/regrid2/Lib/esmf.py
--- cdms-3.1.5/regrid2/Lib/esmf.py 2020-07-31 03:01:33.000000000 +0200
+++ cdms-3.1.5-patch/regrid2/Lib/esmf.py 2021-06-09 15:18:29.043255491 +0200
@@ -18,6 +18,9 @@
import ESMF
from functools import reduce

+from .util import getenv_bool
+
+
# constants
R8 = ESMF.TypeKind.R8
R4 = ESMF.TypeKind.R4
@@ -463,7 +466,13 @@
# communicator
self.comm = None

+ mpi_disabled = getenv_bool("CDMS_NO_MPI", "False")
+
try:
+ # skip trying to load mpi4py module
+ if mpi_disabled:
+ raise Exception()
+
from mpi4py import MPI
self.comm = MPI.COMM_WORLD
except BaseException:
diff -ruN cdms-3.1.5/regrid2/Lib/mvESMFRegrid.py cdms-3.1.5-patch/regrid2/Lib/mvESMFRegrid.py
--- cdms-3.1.5/regrid2/Lib/mvESMFRegrid.py 2020-07-31 03:01:33.000000000 +0200
+++ cdms-3.1.5-patch/regrid2/Lib/mvESMFRegrid.py 2021-06-09 10:40:05.039237116 +0200
@@ -22,9 +22,16 @@
except Exception:
os.environ['MPICH_INTERFACE_HOSTNAME'] = 'localhost'

+from .util import getenv_bool
+
ESMF.Manager(debug=False)
HAVE_MPI = False
+mpi_disabled = getenv_bool("CDMS_NO_MPI", "False")
+
try:
+ # skip trying to load mpi4py module
+ if mpi_disabled:
+ raise Exception()
from mpi4py import MPI
HAVE_MPI = True
except BaseException:
diff -ruN cdms-3.1.5/regrid2/Lib/util.py cdms-3.1.5-patch/regrid2/Lib/util.py
--- cdms-3.1.5/regrid2/Lib/util.py 1970-01-01 01:00:00.000000000 +0100
+++ cdms-3.1.5-patch/regrid2/Lib/util.py 2021-06-09 10:39:10.295311114 +0200
@@ -0,0 +1,16 @@
+import os
+
+
+def getenv_bool(name, default=None):
+ valid_bool_str = ["true", "false"]
+ value = os.environ.get(name, default)
+
+ if value is None:
+ raise ValueError("{!r} was not set".format(name))
+
+ if value.lower() not in valid_bool_str:
+ raise ValueError(
+ "{!r} is not a valid value for {!r}, allowed values: {!r}".format(
+ value, name, valid_bool_str))
+
+ return value.lower() == "true"
3 changes: 2 additions & 1 deletion recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ source:
- 0002-fixes_building_extensions.patch
- 0003-Removes-modifying-ncmode-with-NC_NETCDF4-flag.patch
- 0004-fix_add_env_flag_to_disable_mpi4py.patch
- 0005-env_flag_to_disable_mpi4py_in_regrid2.patch

build:
number: 6
number: 7
skip: True # [win]

requirements:
Expand Down

0 comments on commit 2cd25e8

Please sign in to comment.