Repository: ESMCI/cime

Issue:
build timing library first
I like to alter the build order for the shared libs so the timing library is built first.

Its a simpler library then MCT or PIO so it makes more sense to build it first.  Also this allows adding timers to MCT or PIO if one would like to (in a branch).



Discussion:
I believe that this should be considered in the context of issue #601 

I don't think this needs to be coupled with 601.  The build order is a different decision from which version to build.

True but if you decouple you are going to do much of the same work twice.

I found the one-line change that needed to be made in CIME2 to build libgptl first (so that I can use it to look at performancte in MCT), and have been using this for the past few months. It has been VERY convenient.

Looking at CIME5, I can't see where/how to make a similar change. Any guidance?
I have this on my todo list for cime5 in combination with splitting the csm_share library up, I should be able to get to it soon.   
Well I need it now. Guess that this is not an option. I'll go back to the old way (commenting out all timers in MCT, building, uncommenting, rebuilding.) Sure was simple in CIME2.
I found the location for the change in CIME5, also a one-liner (in cime/utils/python/CIME/build.py). This is all I need. Please do not reprioritize for my sake.

Resolving patch:
diff --git a/utils/python/CIME/build.py b/utils/python/CIME/build.py
--- a/utils/python/CIME/build.py
+++ b/utils/python/CIME/build.py
@@ -423,14 +423,18 @@ def build_libraries(case, exeroot, sharedpath, caseroot, cimeroot, libroot, lid,
     for shared_item in [shared_lib, shared_inc]:
         if (not os.path.exists(shared_item)):
             os.makedirs(shared_item)
-
-    libs = ["mct", "gptl", "pio", "csm_share"]
+    mpilib = case.get_value("MPILIB")
+    libs = ["gptl", "mct", "pio", "csm_share"]
+    if mpilib == "mpi-serial":
+        libs.insert(0, mpilib)
     logs = []
     sharedlibroot = case.get_value("SHAREDLIBROOT")
     for lib in libs:
         if lib == "csm_share":
             # csm_share adds its own dir name
             full_lib_path = os.path.join(sharedlibroot, sharedpath)
+        elif lib == "mpi-serial":
+            full_lib_path = os.path.join(sharedlibroot, sharedpath, "mct", lib)
         else:
             full_lib_path = os.path.join(sharedlibroot, sharedpath, lib)
         # pio build creates its own directory


Test patch:
diff --git a/utils/python/CIME/test_scheduler.py b/utils/python/CIME/test_scheduler.py
--- a/utils/python/CIME/test_scheduler.py
+++ b/utils/python/CIME/test_scheduler.py
@@ -312,7 +312,6 @@ def _create_newcase_phase(self, test):
         if self._output_root is not None:
             create_newcase_cmd += " --output-root %s " % self._output_root
 
-
         if test_mods is not None:
             files = Files()
             (component,modspath) = test_mods.split('/',1)
@@ -457,8 +456,10 @@ def _xml_phase(self, test):
                     os.path.join(lockedfiles, "env_run.orig.xml"))
 
         with Case(test_dir, read_only=False) as case:
+            if self._output_root is None:
+                self._output_root = case.get_value("CIME_OUTPUT_ROOT")
             case.set_value("SHAREDLIBROOT",
-                           os.path.join(self._test_root,
+                           os.path.join(self._output_root,
                                         "sharedlibroot.%s"%self._test_id))
             envtest.set_initial_values(case)
             if self._save_timing: