[m-rev.] for review: Parallelise make_java_csharp_arena_{base, diff}

Peter Wang novalazy at gmail.com
Thu Jul 26 10:40:33 AEST 2018


tools/make_java_csharp_arena_base:
tools/make_java_csharp_arena_diff:
    Use xargs -P to run multiple instances of the compiler in parallel.

    Allow the environment variable PARALLEL to control the number of
    parallel tasks.
---
 tools/make_java_csharp_arena_base | 22 ++++++++++++----------
 tools/make_java_csharp_arena_diff | 19 +++++++++----------
 2 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/tools/make_java_csharp_arena_base b/tools/make_java_csharp_arena_base
index f8de4c538..22aa0d707 100755
--- a/tools/make_java_csharp_arena_base
+++ b/tools/make_java_csharp_arena_base
@@ -21,27 +21,33 @@
 # an instance of tools/lmc). The latter is used by make_java_csharp_diff.
 #
 # This script creates a directory named arena.base that contains
 # all the Mercury source files and interface files from all of the
 # Mercury modules in main Mercury directories of the workspace,
 # and then it puts the known good outputs for the Java and C# grades 
 # in arena.base.java and arena.base.csharp respectively.
 # The companion script make_java_csharp_diff then puts the output
 # of the compiler under test in those grades in arena.java and arena.csharp
 # respectively, and compares them to their respective bases.
+#
+# The environment variable PARALLEL controls the maximum number of compiler
+# processes to run at a time.
 
 if test "${BASE_MMC}" = ""
 then
     echo "make_java_csharp_base: you need to set BASE_MMC in the environment"
     exit 1
 fi
 
+PARALLEL=${PARALLEL:-`nproc 2>/dev/null`}
+PARALLEL=${PARALLEL:-1}
+
 dirs="library mdbcomp browser compiler slice profiler deep_profiler"
 
 root=`/bin/pwd`
 
 cd ${root}
 /bin/rm -fr arena.base arena.base.java arena.base.csharp > /dev/null 2>&1
 
 mkdir arena.base
 for d in ${dirs}
 do
@@ -58,26 +64,22 @@ MODULES_TO_DELETE='
     mode_robdd.tfern.m
     atsort_callgraph.m
 '
 /bin/rm ${MODULES_TO_DELETE}
 
 ${BASE_MMC} -f *.m
 
 cd ${root}
 cp -rp arena.base arena.base.java
 cd ${root}/arena.base.java
-for f in *.m
-do
-    echo === JAVA ${f} ===
-    ${BASE_MMC} --grade java --target-code-only ${f}
-done
+echo === JAVA ===
+echo *.m | xargs -P${PARALLEL} -n1 -t \
+    ${BASE_MMC} --grade java --target-code-only
 
 cd ${root}
 cp -rp arena.base arena.base.csharp
 cd ${root}/arena.base.csharp
-for f in *.m
-do
-    echo === CSHARP ${f} ===
-    ${BASE_MMC} --grade csharp --target-code-only ${f}
-done
+echo === CSHARP ===
+echo *.m | xargs -P${PARALLEL} -n1 -t \
+    ${BASE_MMC} --grade csharp --target-code-only
 
 exit 0
diff --git a/tools/make_java_csharp_arena_diff b/tools/make_java_csharp_arena_diff
index 04c79ec66..c87cf8f4c 100755
--- a/tools/make_java_csharp_arena_diff
+++ b/tools/make_java_csharp_arena_diff
@@ -2,39 +2,38 @@
 # vim: ft=sh ts=4 sw=4 et
 #
 # This script is documented in the companion script make_java_csharp_base.
 
 if test "${TEST_MMC}" = ""
 then
     echo "make_java_csharp_diff: you need to set TEST_MMC in the environment"
     exit 1
 fi
 
+PARALLEL=${PARALLEL:-`nproc 2>/dev/null`}
+PARALLEL=${PARALLEL:-1}
+
 root=`/bin/pwd`
 
 /bin/rm -fr arena.java arena.csharp > /dev/null 2>&1
 cp -rp arena.base arena.java
 cp -rp arena.base arena.csharp
 
 cd ${root}/arena.java
-for f in *.m
-do
-    echo === JAVA ${f} ===
-    ${TEST_MMC} --grade java --target-code-only ${f}
-done
+echo === JAVA ===
+echo *.m | xargs -P${PARALLEL} -n1 -t \
+    ${TEST_MMC} --grade java --target-code-only
 
 cd ${root}/arena.csharp
-for f in *.m
-do
-    echo === CSHARP ${f} ===
-    ${TEST_MMC} --grade csharp --target-code-only ${f}
-done
+echo === CSHARP ===
+echo *.m | xargs -P${PARALLEL} -n1 -t \
+    ${TEST_MMC} --grade csharp --target-code-only
 
 cd ${root}
 diff -ur arena.base.java arena.java > DIFF.ARENA.JAVA 2>&1
 diff -ur arena.base.csharp arena.csharp > DIFF.ARENA.CSHARP 2>&1
 
 echo JAVA DIFF START
 cat DIFF.ARENA.JAVA
 echo JAVA DIFF END
 echo CSHARP DIFF START
 cat DIFF.ARENA.CSHARP
-- 
2.18.0



More information about the reviews mailing list