Isca icon indicating copy to clipboard operation
Isca copied to clipboard

fail to build on Mac OS (via py.test or otherwise)

Open gaelforget opened this issue 3 years ago • 5 comments

Description

My attempts to compile Isca on a Mac OS have failed, so for now I give up. Until this issue is fixed (and unless I am just confused) my suggestion would be that you add a warning in the docs & README.md that Isca can only be built on a linux machine (not on Mac).

At first I tried as explained in the README (i.e. via held_suarez_test_case.py) and then as explained in the docs (i.e. via py.test).

I get error messages that have to do with system calls that seem specific for linux:

  • ulimit -s unlimited in src/extra/python/isca/templates/compile.sh
  • syscall(__NR_gettid) in src/shared/mpp/affinity.c
  • cpu_set_t, CPU_ZERO, coremask, etc also in mpp/affinity.c

The patch below shows what I did to get past the first two errors based on finding this post.

I also found this other post by @ntlewis , I think, which links to this potential solution.

git diff / patch I tried

--- a/src/extra/python/isca/templates/compile.sh
+++ b/src/extra/python/isca/templates/compile.sh
@@ -20,7 +20,7 @@ executable={{ executable_name }}

 netcdf_flags=`nf-config --fflags --flibs`

-ulimit -s unlimited # Set stack size to unlimited
+#ulimit -s unlimited # Set stack size to unlimited
 export MALLOC_CHECK_=0

 # 3. compile the mppncombine tool if it hasn't yet been done.
diff --git a/src/shared/mpp/affinity.c b/src/shared/mpp/affinity.c
index f0eb781..e165365 100644
--- a/src/shared/mpp/affinity.c
+++ b/src/shared/mpp/affinity.c
@@ -30,9 +30,13 @@
 #include <sys/resource.h>
 #include <sys/syscall.h>

+#include <pthread.h>
+
 static pid_t gettid(void)
 {
-  return syscall(__NR_gettid);
+  uint64_t tid64;
+  pthread_threadid_np(NULL, &tid64);
+  return (pid_t)tid64;
 }

 /*

gaelforget avatar Jun 07 '21 17:06 gaelforget

Just to note - a few years ago we (i.e. @jamesp) did build and run it on a Mac, both natively (using gfortran) and perhaps also by way of Docker (although using Docker might be regarded as cheating). We never pursued this as we had no need at the time and unfortunately never documented it properly, for which apologies. It may also be that in the meantime the MacOS has changed. I'll ask around to see if there is a valid current solution.

gkvallis avatar Jun 07 '21 18:06 gkvallis

@gaelforget It's worth checking out this branch on @jamesp's fork which includes a small modification to allow Isca to run natively on Mac: https://github.com/jamesp/Isca/tree/mac.

From an old discussion with Jamie: "for now I've just stubbed out the affinity checks. It might be worth doing some more research and working out if it is possible to pin threads to specific cores. may make a speed improvement".

I don't know if this fix still works, but @sit23 had something very similar working around a year ago. Might depend on how modern your Mac is (i.e., I don't know if something will go really wrong if you have an Apple-silicon Mac). I've never actually run this myself, so this is as helpful as I can be. Good luck!

ntlewis avatar Jun 08 '21 08:06 ntlewis

Thanks!!

I think I got it working after a bit of trial and error(s). The patch is in https://github.com/ExeClim/Isca/pull/211 (more detail there)

For context, I am looking at Isca as a potential candidate for the initial model example suite of ClimateModels.jl. Now that I have a working Mac version I can take a deeper look on my local machine and hope to try the Julia interface in coming days.

Next step would be to try a small config on https://mybinder.org as I would utlimately need to use https://travis-ci.org for routine CI + part of my goal is to offer an interactive cloud-based experience to users. Am wondering if Isca devs are already doing that for their own CI and demos. Happy to open a separate issue on this later if preferred but I figured I might as well mention it here.

gaelforget avatar Jun 11 '21 16:06 gaelforget

@gaelforget Thanks for taking a look at this. It will be good to have a set up for Isca that works on Mac in the master!

ntlewis avatar Jun 11 '21 16:06 ntlewis

@gaelforget I added a basic CI for Isca via Travis, but I was actually thinking of moving it to Github workflows instead. With your (initial) problems on MacOS in mind, we should add a CI job for MacOS. I don't use Mac myself, so it would be a bit more cumbersome for me to test this setup, so any help is appreciated.

An interactive example on mybinder would be also cool, I'm happy to review a PR if you suggest one.

dennissergeev avatar Jun 11 '21 16:06 dennissergeev