From 22564b51633fa0d34b9ed5e437670f93f8cb7add Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20Dehenne?= <remi.dehenne@cea.fr>
Date: Thu, 22 Dec 2022 10:45:51 +0100
Subject: [PATCH] Add MPC Framework recipe

---
 Custom_EasyBlocks/mpcframework.py             | 27 ++++++++++++
 .../MPCFramework-4.2.0-GCC-11.3.0.eb          | 43 +++++++++++++++++++
 Golden_Repo/m/MPCFramework/nvdimm.patch       | 26 +++++++++++
 3 files changed, 96 insertions(+)
 create mode 100644 Custom_EasyBlocks/mpcframework.py
 create mode 100644 Golden_Repo/m/MPCFramework/MPCFramework-4.2.0-GCC-11.3.0.eb
 create mode 100644 Golden_Repo/m/MPCFramework/nvdimm.patch

diff --git a/Custom_EasyBlocks/mpcframework.py b/Custom_EasyBlocks/mpcframework.py
new file mode 100644
index 000000000..e3c3fec2e
--- /dev/null
+++ b/Custom_EasyBlocks/mpcframework.py
@@ -0,0 +1,27 @@
+from easybuild.easyblocks.generic.binary import Binary
+
+import os.path
+
+
+class EB_MPCFramework(Binary):
+    """Support for building/installing the MPC Framework."""
+
+    def make_module_extra(self):
+        """Correctly prepend $PYTHONPATH and set environment variables for MPC Framework. Equivalent to mpcvars.sh."""
+
+        txt = super(EB_MPCFramework, self).make_module_extra()
+
+        txt += self.module_generator.set_environment(
+            "MPC_INSTALL_DIR_PREFIX", self.installdir)
+        txt += self.module_generator.set_environment(
+            "MPC_VERSION", self.version)
+
+        # Variables such as $PATH, $CPATH or $LD_LIBRARY_PATH are already set
+        # by default by EasyBuild.
+        txt += self.module_generator.prepend_paths(
+            "PYTHONPATH", ['lib/python/', 'lib64/python/'])
+
+        txt += self.module_generator.set_environment(
+            "MPCFRAMEWORK_DIR", self.installdir + 'share/mpcframework/cmake/')
+
+        return txt
diff --git a/Golden_Repo/m/MPCFramework/MPCFramework-4.2.0-GCC-11.3.0.eb b/Golden_Repo/m/MPCFramework/MPCFramework-4.2.0-GCC-11.3.0.eb
new file mode 100644
index 000000000..ea0dc680a
--- /dev/null
+++ b/Golden_Repo/m/MPCFramework/MPCFramework-4.2.0-GCC-11.3.0.eb
@@ -0,0 +1,43 @@
+name = 'MPCFramework'
+version = '4.2.0'
+
+homepage = 'https://mpc.hpcframework.com'
+description = """An Implementation of MPI and OpenMP relying on user-level threads"""
+
+toolchain = {'name': 'GCC', 'version': '11.3.0'}
+
+source_urls = [
+    'https://github.com/cea-hpc/mpc/archive/refs/tags/'
+]
+
+sources = ['MPC_%(version)s.zip']
+checksums = [
+    # MPC_4.2.0.zip
+    'd2610173cf0bf8f64985bc45602c133ca0beaff78c8bea7fe35fda771ceae5ca',
+]
+
+patches = ['nvdimm.patch']
+
+builddependencies = [
+    ('CMake', '3.23.1'),
+    ('bzip2', '1.0.8', '', ('GCCcore', '11.3.0')),
+    ('cURL', '7.83.0'),
+    ('help2man', '1.49.2'),
+    ('OpenSSL', '1.1', '', SYSTEM),
+]
+
+installopts = '--prefix=%(installdir)s -j%(parallel)s --enable-color --disable-spack --disable-spack-build --mpc-option="--without-portals" '
+
+# To enable SLURM integration (site-specific)
+installopts += '--with-pmix '
+
+sanity_check_commands = [
+    "mpcrun --help",
+    "mpc_print_config"
+]
+
+moduleclass = 'devel'
+
+# Options passed to the Binary EasyBlock (superclass of the MPCFramework EasyBlock)
+extract_sources = True
+install_cmd = 'mkdir BUILD && cd BUILD && ../installmpc'
diff --git a/Golden_Repo/m/MPCFramework/nvdimm.patch b/Golden_Repo/m/MPCFramework/nvdimm.patch
new file mode 100644
index 000000000..61cadd0d9
--- /dev/null
+++ b/Golden_Repo/m/MPCFramework/nvdimm.patch
@@ -0,0 +1,26 @@
+[PATCH] LAUNCH: Fix mpcrun --help crash with NVDIMM
+author: Remi Dehenne
+
+mpcrun --help no longer crashes when mpc_print_config displays
+`<Topology> NVDIMM Found ! (OS Device #xx)` messages.
+Those messages are now printed on stderr with
+mpc_common_debug_log, rather than with fprintf on stdout.
+---
+ src/MPC_Topology/src/topology.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/MPC_Topology/src/topology.c b/src/MPC_Topology/src/topology.c
+index e62cbcb01..9172c6de2 100644
+--- a/src/MPC_Topology/src/topology.c
++++ b/src/MPC_Topology/src/topology.c
+@@ -1376,7 +1376,7 @@ void _mpc_topology_nvdimm_detection(hwloc_topology_t topology)
+ 		{
+ 			if(strcmp(current->subtype, "NVDIMM") == 0)
+ 			{
+-				fprintf(stdout, "<Topology> %s Found ! (OS Device #%d)\n", current->subtype, current->logical_index);
++				mpc_common_debug_log("<Topology> %s Found ! (OS Device #%d)\n", current->subtype, current->logical_index);
+ 				++__mpc_module_avail_nvdimm;
+ 			}
+ 		}
+-- 
+
-- 
GitLab