From bd8d24ebbcffc8bebffe0e3a0ab5edaabbbf090f Mon Sep 17 00:00:00 2001
From: Guillaume-Helbecque <helbecque.guillaume@gmail.com>
Date: Wed, 2 Apr 2025 14:34:38 +0200
Subject: [PATCH] implement helper messages

---
 lib/common/util.chpl            | 10 ++++++++++
 nqueens_chpl.chpl               | 20 +++++++++++++++++++-
 nqueens_dist_multigpu_chpl.chpl | 20 +++++++++++++++++++-
 nqueens_gpu_chpl.chpl           | 20 +++++++++++++++++++-
 nqueens_multigpu_chpl.chpl      | 20 +++++++++++++++++++-
 pfsp_chpl.chpl                  | 21 ++++++++++++++++++++-
 pfsp_dist_multigpu_chpl.chpl    | 21 ++++++++++++++++++++-
 pfsp_gpu_chpl.chpl              | 21 ++++++++++++++++++++-
 pfsp_multigpu_chpl.chpl         | 20 +++++++++++++++++++-
 9 files changed, 165 insertions(+), 8 deletions(-)

diff --git a/lib/common/util.chpl b/lib/common/util.chpl
index 4cdf5f7..a2b2470 100644
--- a/lib/common/util.chpl
+++ b/lib/common/util.chpl
@@ -28,4 +28,14 @@ module util
       }
     }
   }
+
+  proc common_help_message(): void
+  {
+    writeln("\n    usage:  main.out [parameter value] ...");
+    writeln("\n  General Parameters:\n");
+    writeln("   --m              int   minimum number of elements to offload on a GPU device");
+    writeln("   --M              int   maximum number of elements to offload on a GPU device");
+    writeln("   --D              int   number of GPU device(s)");
+    writeln("   --help (or -h)         this message");
+  }
 }
diff --git a/nqueens_chpl.chpl b/nqueens_chpl.chpl
index 0c472ce..2ea9cbe 100644
--- a/nqueens_chpl.chpl
+++ b/nqueens_chpl.chpl
@@ -4,6 +4,7 @@
 
 use Time;
 
+use util;
 use Pool;
 
 use NQueens_node;
@@ -40,6 +41,13 @@ proc print_results(const exploredTree: uint, const exploredSol: uint, const time
   writeln("=================================================\n");
 }
 
+proc help_message(): void
+{
+  writeln("\n  N-Queens Benchmark Parameters:\n");
+  writeln("   --N   int   number of queens");
+  writeln("   --g   int   number of safety check(s) per evaluation\n");
+}
+
 // Check queen's safety.
 proc isSafe(const board, const queen_num, const row_pos): uint(8)
 {
@@ -105,8 +113,18 @@ proc nqueens_search(ref exploredTree: uint, ref exploredSol: uint, ref elapsedTi
   writeln("\nExploration terminated.");
 }
 
-proc main()
+proc main(args: [] string)
 {
+  // Helper
+  for a in args[1..] {
+    if (a == "-h" || a == "--help") {
+      common_help_message();
+      help_message();
+
+      return 1;
+    }
+  }
+
   check_parameters();
   print_settings();
 
diff --git a/nqueens_dist_multigpu_chpl.chpl b/nqueens_dist_multigpu_chpl.chpl
index be3e763..ef48df5 100644
--- a/nqueens_dist_multigpu_chpl.chpl
+++ b/nqueens_dist_multigpu_chpl.chpl
@@ -4,6 +4,7 @@
 
 use Time;
 
+use util;
 use Pool;
 use Pool_par;
 use PrivateDist;
@@ -48,6 +49,13 @@ proc print_results(const exploredTree: uint, const exploredSol: uint, const time
   writeln("=================================================\n");
 }
 
+proc help_message(): void
+{
+  writeln("\n  N-Queens Benchmark Parameters:\n");
+  writeln("   --N   int   number of queens");
+  writeln("   --g   int   number of safety check(s) per evaluation\n");
+}
+
 // Check queen's safety.
 proc isSafe(const board, const queen_num, const row_pos): uint(8)
 {
@@ -327,8 +335,18 @@ proc nqueens_search(ref exploredTree: uint, ref exploredSol: uint, ref elapsedTi
   writeln("\nExploration terminated.");
 }
 
-proc main()
+proc main(args: [] string)
 {
+  // Helper
+  for a in args[1..] {
+    if (a == "-h" || a == "--help") {
+      common_help_message();
+      help_message();
+
+      return 1;
+    }
+  }
+
   check_parameters();
   print_settings();
 
diff --git a/nqueens_gpu_chpl.chpl b/nqueens_gpu_chpl.chpl
index eca737d..cede274 100644
--- a/nqueens_gpu_chpl.chpl
+++ b/nqueens_gpu_chpl.chpl
@@ -4,6 +4,7 @@
 
 use Time;
 
+use util;
 use Pool;
 use GpuDiagnostics;
 
@@ -45,6 +46,13 @@ proc print_results(const exploredTree: uint, const exploredSol: uint, const time
   writeln("=================================================\n");
 }
 
+proc help_message(): void
+{
+  writeln("\n  N-Queens Benchmark Parameters:\n");
+  writeln("   --N   int   number of queens");
+  writeln("   --g   int   number of safety check(s) per evaluation\n");
+}
+
 // Check queen's safety.
 proc isSafe(const board, const queen_num, const row_pos): uint(8)
 {
@@ -192,8 +200,18 @@ proc nqueens_search(ref exploredTree: uint, ref exploredSol: uint, ref elapsedTi
   writeln("\nExploration terminated.");
 }
 
-proc main()
+proc main(args: [] string)
 {
+  // Helper
+  for a in args[1..] {
+    if (a == "-h" || a == "--help") {
+      common_help_message();
+      help_message();
+
+      return 1;
+    }
+  }
+
   check_parameters();
   print_settings();
 
diff --git a/nqueens_multigpu_chpl.chpl b/nqueens_multigpu_chpl.chpl
index fb0ce31..bd6b335 100644
--- a/nqueens_multigpu_chpl.chpl
+++ b/nqueens_multigpu_chpl.chpl
@@ -4,6 +4,7 @@
 
 use Time;
 
+use util;
 use Pool;
 use GpuDiagnostics;
 
@@ -46,6 +47,13 @@ proc print_results(const exploredTree: uint, const exploredSol: uint, const time
   writeln("=================================================\n");
 }
 
+proc help_message(): void
+{
+  writeln("\n  N-Queens Benchmark Parameters:\n");
+  writeln("   --N   int   number of queens");
+  writeln("   --g   int   number of safety check(s) per evaluation\n");
+}
+
 // Check queen's safety.
 proc isSafe(const board, const queen_num, const row_pos): uint(8)
 {
@@ -282,8 +290,18 @@ proc nqueens_search(ref exploredTree: uint, ref exploredSol: uint, ref elapsedTi
   writeln("\nExploration terminated.");
 }
 
-proc main()
+proc main(args: [] string)
 {
+  // Helper
+  for a in args[1..] {
+    if (a == "-h" || a == "--help") {
+      common_help_message();
+      help_message();
+
+      return 1;
+    }
+  }
+
   check_parameters();
   print_settings();
 
diff --git a/pfsp_chpl.chpl b/pfsp_chpl.chpl
index 7204930..2cbc2ad 100644
--- a/pfsp_chpl.chpl
+++ b/pfsp_chpl.chpl
@@ -4,6 +4,7 @@
 
 use Time;
 
+use util;
 use Pool;
 
 use PFSP_node;
@@ -76,6 +77,14 @@ proc print_results(const optimum: int, const exploredTree: uint, const exploredS
   writeln("=================================================\n");
 }
 
+proc help_message(): void
+{
+  writeln("\n  PFSP Benchmark Parameters:\n");
+  writeln("   --inst   int   Taillard's instance to solve (between 001 and 120)");
+  writeln("   --lb     str   lower bound function (lb1, lb1_d, lb2)");
+  writeln("   --ub     int   initial upper bound (0, 1)\n");
+}
+
 // Evaluate and generate children nodes on CPU.
 proc decompose_lb1(const parent: Node, ref tree_loc: uint, ref num_sol: uint,
   ref best: int, ref pool: SinglePool(Node))
@@ -206,8 +215,18 @@ proc pfsp_search(ref optimum: int, ref exploredTree: uint, ref exploredSol: uint
   writeln("\nExploration terminated.");
 }
 
-proc main()
+proc main(args: [] string)
 {
+  // Helper
+  for a in args[1..] {
+    if (a == "-h" || a == "--help") {
+      common_help_message();
+      help_message();
+
+      return 1;
+    }
+  }
+
   check_parameters();
   print_settings();
 
diff --git a/pfsp_dist_multigpu_chpl.chpl b/pfsp_dist_multigpu_chpl.chpl
index d2410e3..7281675 100644
--- a/pfsp_dist_multigpu_chpl.chpl
+++ b/pfsp_dist_multigpu_chpl.chpl
@@ -8,6 +8,7 @@ use GpuDiagnostics;
 
 config const BLOCK_SIZE = 512;
 
+use util;
 use Pool_par;
 
 use PFSP_node;
@@ -78,6 +79,14 @@ proc print_results(const optimum: int, const exploredTree: uint, const exploredS
   writeln("=================================================\n");
 }
 
+proc help_message(): void
+{
+  writeln("\n  PFSP Benchmark Parameters:\n");
+  writeln("   --inst   int   Taillard's instance to solve (between 001 and 120)");
+  writeln("   --lb     str   lower bound function (lb1, lb1_d, lb2)");
+  writeln("   --ub     int   initial upper bound (0, 1)\n");
+}
+
 // Evaluate and generate children nodes on CPU.
 proc decompose_lb1(const lb1_data, const parent: Node, ref tree_loc: uint, ref num_sol: uint,
   ref best: int, ref pool: SinglePool_par(Node))
@@ -515,8 +524,18 @@ proc pfsp_search(ref optimum: int, ref exploredTree: uint, ref exploredSol: uint
   writeln("\nExploration terminated.");
 }
 
-proc main()
+proc main(args: [] string)
 {
+  // Helper
+  for a in args[1..] {
+    if (a == "-h" || a == "--help") {
+      common_help_message();
+      help_message();
+
+      return 1;
+    }
+  }
+
   check_parameters();
   print_settings();
 
diff --git a/pfsp_gpu_chpl.chpl b/pfsp_gpu_chpl.chpl
index 1b85273..617f9ce 100644
--- a/pfsp_gpu_chpl.chpl
+++ b/pfsp_gpu_chpl.chpl
@@ -7,6 +7,7 @@ use GpuDiagnostics;
 
 config const BLOCK_SIZE = 512;
 
+use util;
 use Pool;
 
 use PFSP_node;
@@ -85,6 +86,14 @@ proc print_results(const optimum: int, const exploredTree: uint, const exploredS
   writeln("=================================================\n");
 }
 
+proc help_message(): void
+{
+  writeln("\n  PFSP Benchmark Parameters:\n");
+  writeln("   --inst   int   Taillard's instance to solve (between 001 and 120)");
+  writeln("   --lb     str   lower bound function (lb1, lb1_d, lb2)");
+  writeln("   --ub     int   initial upper bound (0, 1)\n");
+}
+
 // Evaluate and generate children nodes on CPU.
 proc decompose_lb1(const parent: Node, ref tree_loc: uint, ref num_sol: uint,
   ref best: int, ref pool: SinglePool(Node))
@@ -442,8 +451,18 @@ proc pfsp_search(ref optimum: int, ref exploredTree: uint, ref exploredSol: uint
   writeln("\nExploration terminated.");
 }
 
-proc main()
+proc main(args: [] string)
 {
+  // Helper
+  for a in args[1..] {
+    if (a == "-h" || a == "--help") {
+      common_help_message();
+      help_message();
+
+      return 1;
+    }
+  }
+
   check_parameters();
   print_settings();
 
diff --git a/pfsp_multigpu_chpl.chpl b/pfsp_multigpu_chpl.chpl
index 7fb9802..2bb3ae2 100644
--- a/pfsp_multigpu_chpl.chpl
+++ b/pfsp_multigpu_chpl.chpl
@@ -79,6 +79,14 @@ proc print_results(const optimum: int, const exploredTree: uint, const exploredS
   writeln("=================================================\n");
 }
 
+proc help_message(): void
+{
+  writeln("\n  PFSP Benchmark Parameters:\n");
+  writeln("   --inst   int   Taillard's instance to solve (between 001 and 120)");
+  writeln("   --lb     str   lower bound function (lb1, lb1_d, lb2)");
+  writeln("   --ub     int   initial upper bound (0, 1)\n");
+}
+
 // Evaluate and generate children nodes on CPU.
 proc decompose_lb1(const lb1_data, const parent: Node, ref tree_loc: uint, ref num_sol: uint,
   ref best: int, ref pool: SinglePool_par(Node))
@@ -571,8 +579,18 @@ proc pfsp_search(ref optimum: int, ref exploredTree: uint, ref exploredSol: uint
   writeln("\nExploration terminated.");
 }
 
-proc main()
+proc main(args: [] string)
 {
+  // Helper
+  for a in args[1..] {
+    if (a == "-h" || a == "--help") {
+      common_help_message();
+      help_message();
+
+      return 1;
+    }
+  }
+
   check_parameters();
   print_settings();
 
-- 
GitLab