Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'add_semaphore_python_bindings' into 'master'
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 17 Mar 2022 20:19:06 +0000 (20:19 +0000)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 17 Mar 2022 20:19:06 +0000 (20:19 +0000)
Add Semaphore Python bindings

See merge request simgrid/simgrid!91

14 files changed:
include/simgrid/s4u/ConditionVariable.hpp
include/simgrid/s4u/Mutex.hpp
include/xbt/automaton.hpp
include/xbt/functional.hpp
src/include/xbt/parmap.hpp
src/kernel/activity/ActivityImpl.hpp
src/kernel/activity/ExecImpl.hpp
src/kernel/actor/ActorImpl.hpp
src/kernel/resource/profile/Profile.cpp
src/smpi/include/smpi_file.hpp
teshsuite/smpi/MBI/MBI.py
teshsuite/smpi/MBI/MBIutils.py
teshsuite/smpi/MBI/generator_utils.py
teshsuite/smpi/MBI/simgrid.py

index 82d16d8..d090776 100644 (file)
@@ -28,7 +28,7 @@ class XBT_PUBLIC ConditionVariable {
 private:
 #ifndef DOXYGEN
   friend kernel::activity::ConditionVariableImpl;
-  friend void kernel::activity::intrusive_ptr_release(kernel::activity::ConditionVariableImpl* cond);
+  friend XBT_PUBLIC void kernel::activity::intrusive_ptr_release(kernel::activity::ConditionVariableImpl* cond);
 #endif
 
   kernel::activity::ConditionVariableImpl* const pimpl_;
index 8418ca9..cebeca7 100644 (file)
@@ -32,7 +32,7 @@ class XBT_PUBLIC Mutex {
 #ifndef DOXYGEN
   friend ConditionVariable;
   friend kernel::activity::MutexImpl;
-  friend void kernel::activity::intrusive_ptr_release(kernel::activity::MutexImpl* mutex);
+  friend XBT_PUBLIC void kernel::activity::intrusive_ptr_release(kernel::activity::MutexImpl* mutex);
 #endif
 
   kernel::activity::MutexImpl* const pimpl_;
index 49d55f5..8c4ac2e 100644 (file)
@@ -23,7 +23,7 @@ template <class F> xbt_automaton_propositional_symbol_t add_proposition(const_xb
 {
   auto* callback = new F(std::move(f));
   return xbt_automaton_propositional_symbol_new_callback(
-      a, id, [](void* cb) -> int { return (*(F*)cb)(); }, callback, [](void* cb) -> void { delete (F*)cb; });
+      a, id, [](auto* cb) -> int { return (*(F*)cb)(); }, callback, [](auto* cb) -> void { delete (F*)cb; });
 }
 
 }
index 1bb1e36..9509d49 100644 (file)
@@ -37,11 +37,10 @@ public:
   }
   void operator()() const
   {
-    const int argc                = args_->size();
     std::vector<std::string> args = *args_;
     std::vector<char*> argv(args.size() + 1); // argv[argc] is nullptr
     std::transform(begin(args), end(args), begin(argv), [](std::string& s) { return &s.front(); });
-    code_(argc, argv.data());
+    code_(static_cast<int>(args.size()), argv.data());
   }
 };
 
index 9cebe1d..48ce17e 100644 (file)
@@ -238,7 +238,7 @@ template <typename T> boost::optional<T> Parmap<T>::next()
  */
 template <typename T> void Parmap<T>::work()
 {
-  unsigned length = common_data->size();
+  unsigned length = static_cast<unsigned>(common_data->size());
   unsigned index  = common_index.fetch_add(1, std::memory_order_relaxed);
   while (index < length) {
     worker_fun((*common_data)[index]);
index 5edb48e..68126bc 100644 (file)
@@ -90,7 +90,7 @@ public:
   // Support for the boost::intrusive_ptr<ActivityImpl> datatype
   friend XBT_PUBLIC void intrusive_ptr_add_ref(ActivityImpl* activity);
   friend XBT_PUBLIC void intrusive_ptr_release(ActivityImpl* activity);
-  int get_refcount() const { return refcount_; } // For debugging purpose
+  int get_refcount() const { return static_cast<int>(refcount_); } // For debugging purpose
 
   static xbt::signal<void(ActivityImpl const&)> on_suspended;
   static xbt::signal<void(ActivityImpl const&)> on_resumed;
index f69b6ee..7133154 100644 (file)
@@ -46,7 +46,7 @@ public:
   ExecImpl& set_thread_count(int thread_count);
   ExecImpl& set_hosts(const std::vector<s4u::Host*>& hosts);
 
-  unsigned int get_host_number() const { return hosts_.size(); }
+  unsigned int get_host_number() const { return static_cast<unsigned>(hosts_.size()); }
   double get_seq_remaining_ratio();
   double get_par_remaining_ratio();
   double get_remaining() const override;
index 9979c40..d822f6d 100644 (file)
@@ -114,7 +114,7 @@ private:
   std::atomic_int_fast32_t refcount_{0};
 
 public:
-  int get_refcount() const { return refcount_; }
+  int get_refcount() const { return static_cast<int>(refcount_); }
   friend void intrusive_ptr_add_ref(ActorImpl* actor)
   {
     // This whole memory consistency semantic drives me nuts.
index 3422094..0f17aa7 100644 (file)
@@ -42,10 +42,9 @@ Event* Profile::schedule(FutureEvtSet* fes, resource::Resource* resource)
     cb(event_list);
 
   if(event_list.empty()) {
-    event->free_me  = false;
+    event->free_me  = true;
+    tmgr_trace_event_unref(&event);
   } else {
-    //FIXME: This is a bug, but keep old behaviour for now
-    //fes_->add_event(0, event);
     fes_->add_event(event_list[0].date_, event);
   }
   return event;
index bfd883c..3d1384b 100644 (file)
@@ -165,13 +165,13 @@ int File::op_all(void* buf, int count, const Datatype* datatype, MPI_Status* sta
   }
   // what do I need to read ?
   MPI_Offset totreads = 0;
-  for (unsigned i = 0; i < chunks.size(); i++) {
-    if (chunks[i].second < my_chunk_start)
+  for (auto const& chunk : chunks) {
+    if (chunk.second < my_chunk_start)
       continue;
-    else if (chunks[i].first > my_chunk_end)
+    else if (chunk.first > my_chunk_end)
       continue;
     else
-      totreads += (std::min(chunks[i].second, my_chunk_end - 1) - std::max(chunks[i].first, my_chunk_start));
+      totreads += (std::min(chunk.second, my_chunk_end - 1) - std::max(chunk.first, my_chunk_start));
   }
   XBT_CDEBUG(smpi_pmpi, "will have to access %lld from my chunk", totreads);
 
index bed5d75..9c384a4 100755 (executable)
@@ -9,7 +9,6 @@
 
 import sys
 import os
-import re
 
 from MBIutils import *
 import simgrid
@@ -31,10 +30,10 @@ simgrid = simgrid.Tool()
 
 (name, path, binary, filename) = sys.argv
 for test in parse_one_code(filename):
-    execcmd = re.sub("mpirun", f"{path}/smpi_script/bin/smpirun -wrapper '{path}/bin/simgrid-mc --log=mc_safety.t:info' -platform ./cluster.xml -analyze --cfg=smpi/finalization-barrier:on --cfg=smpi/list-leaks:10 --cfg=model-check/max-depth:10000", test['cmd'])
-    execcmd = re.sub('\${EXE}', binary, execcmd)
-    execcmd = re.sub('\$zero_buffer', "--cfg=smpi/buffering:zero", execcmd)
-    execcmd = re.sub('\$infty_buffer', "--cfg=smpi/buffering:infty", execcmd)
+    execcmd = test['cmd'].replace("mpirun", f"{path}/smpi_script/bin/smpirun -wrapper '{path}/bin/simgrid-mc --log=mc_safety.t:info' -platform ./cluster.xml -analyze --cfg=smpi/finalization-barrier:on --cfg=smpi/list-leaks:10 --cfg=model-check/max-depth:10000")
+    execcmd = execcmd.replace('${EXE}', binary)
+    execcmd = execcmd.replace('$zero_buffer', "--cfg=smpi/buffering:zero")
+    execcmd = execcmd.replace('$infty_buffer', "--cfg=smpi/buffering:infty")
 
     if os.path.exists(f'{filename}.txt'):
         os.remove(f'{filename}.txt')
@@ -46,4 +45,4 @@ for test in parse_one_code(filename):
     if res_category != "TRUE_NEG" and res_category != "TRUE_POS":
         print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n")
         print(f"SimGrid gave the wrong result ({outcome} instead of {test['expect']}).")
-        sys.exit(1)
\ No newline at end of file
+        sys.exit(1)
index 433466f..070d321 100644 (file)
@@ -113,12 +113,12 @@ def parse_one_code(filename):
                 if state == 0:
                     state = 1
                 else:
-                    raise Exception(f"MBI_TESTS header appears a second time at line {line_num}: \n{line}")
+                    raise ValueError(f"MBI_TESTS header appears a second time at line {line_num}: \n{line}")
             elif re.match(".*END_MBI_TESTS.*", line):
                 if state == 1:
                     state = 2
                 else:
-                    raise Exception(f"Unexpected end of MBI_TESTS header at line {line_num}: \n{line}")
+                    raise ValueError(f"Unexpected end of MBI_TESTS header at line {line_num}: \n{line}")
             if state == 1 and re.match("\s+\$ ?.*", line):
                 m = re.match('\s+\$ ?(.*)', line)
                 cmd = m.group(1)
@@ -129,12 +129,12 @@ def parse_one_code(filename):
                 else:
                     m = re.match('[ |]*ERROR: *(.*)', nextline)
                     if not m:
-                        raise Exception(
+                        raise ValueError(
                             f"\n{filename}:{line_num}: MBI parse error: Test not followed by a proper 'ERROR' line:\n{line}{nextline}")
                     expect = 'ERROR'
                     detail = m.group(1)
                     if detail not in possible_details:
-                        raise Exception(
+                        raise ValueError(
                             f"\n{filename}:{line_num}: MBI parse error: Detailled outcome {detail} is not one of the allowed ones.")
                 test = {'filename': filename, 'id': test_num, 'cmd': cmd, 'expect': expect, 'detail': detail}
                 res.append(test.copy())
@@ -142,12 +142,12 @@ def parse_one_code(filename):
                 line_num += 1
 
     if state == 0:
-        raise Exception(f"MBI_TESTS header not found in file '{filename}'.")
+        raise ValueError(f"MBI_TESTS header not found in file '{filename}'.")
     if state == 1:
-        raise Exception(f"MBI_TESTS header not properly ended in file '{filename}'.")
+        raise ValueError(f"MBI_TESTS header not properly ended in file '{filename}'.")
 
     if len(res) == 0:
-        raise Exception(f"No test found in {filename}. Please fix it.")
+        raise ValueError(f"No test found in {filename}. Please fix it.")
     return res
 
 def categorize(tool, toolname, test_id, expected):
@@ -157,7 +157,7 @@ def categorize(tool, toolname, test_id, expected):
         if outcome == 'failure':
             elapsed = 0
         else:
-            raise Exception(f"Invalid test result: {test_id}.txt exists but not {test_id}.elapsed")
+            raise ValueError(f"Invalid test result: {test_id}.txt exists but not {test_id}.elapsed")
     else:
         with open(f'{test_id}.elapsed' if os.path.exists(f'{test_id}.elapsed') else f'logs/{toolname}/{test_id}.elapsed', 'r') as infile:
             elapsed = infile.read()
@@ -193,7 +193,7 @@ def categorize(tool, toolname, test_id, expected):
             res_category = 'TRUE_POS'
             diagnostic =  f'correctly detected an error'
     else:
-        raise Exception(f"Unexpected expectation: {expected} (must be OK or ERROR)")
+        raise ValueError(f"Unexpected expectation: {expected} (must be OK or ERROR)")
 
     return (res_category, elapsed, diagnostic, outcome)
 
index e978b1e..3ef5d5c 100644 (file)
@@ -433,12 +433,12 @@ def find_line(content, target, filename):
             #print(f'Found {target} at {line}')
             return res
         res += 1
-    raise Exception(f"Line target {target} not found in {filename}.")
+    raise ValueError(f"Line target {target} not found in {filename}.")
 
 
 def make_file(template, filename, replace):
     output = template
-    filename = re.sub("_MPI_", "_", filename)
+    filename = filename.replace("_MPI_", "_")
     replace['filename'] = filename
     # Replace all variables that don't have a ':' in their name
     while re.search("@\{[^@:]*\}@", output):
@@ -449,7 +449,7 @@ def make_file(template, filename, replace):
             output = re.sub(f'@\{{{target}\}}@', replace[target], output)
             #print(f"Replace {target} -> {replace[target]}")
         else:
-            raise Exception(f"Variable {target} used in template, but not defined.")
+            raise ValueError(f"Variable {target} used in template, but not defined.")
     # Now replace all variables with a ':' in their name: line targets are like that, and we don't want to resolve them before the others change the lines
     while re.search("@\{([^:@]*):([^@]*)\}@", output):
         m = re.search("@\{([^:@]*):([^@]*)\}@", output)
@@ -459,7 +459,7 @@ def make_file(template, filename, replace):
             #print(f"Replace @{{line:{target}}}@ with '{replace}'")
             output = re.sub(f'@\{{line:{target}\}}@', replace, output)
         else:
-            raise Exception(f"Unknown variable kind: {kind}:{target}")
+            raise ValueError(f"Unknown variable kind: {kind}:{target}")
 
     if os.path.exists(filename):
         with open(filename, 'r') as file:
index b4f4158..049ece1 100644 (file)
@@ -48,12 +48,12 @@ class Tool(AbstractTool):
                 outfile.write(' <cluster id="acme" prefix="node-" radical="0-99" suffix="" speed="1Gf" bw="125MBps" lat="50us"/>\n')
                 outfile.write('</platform>\n')
 
-        execcmd = re.sub("mpirun", "smpirun -wrapper simgrid-mc -platform ./cluster.xml -analyze --cfg=smpi/finalization-barrier:on --cfg=smpi/list-leaks:10 --cfg=model-check/max-depth:10000", execcmd)
+        execcmd = execcmd.replace("mpirun", "smpirun -wrapper simgrid-mc -platform ./cluster.xml -analyze --cfg=smpi/finalization-barrier:on --cfg=smpi/list-leaks:10 --cfg=model-check/max-depth:10000")
         if re.search("Concurrency", binary):  # DPOR reduction in simgrid cannot deal with RMA calls as they contain mutexes
-            execcmd = re.sub("smpirun", "smpirun --cfg=model-check/reduction:none", execcmd)
-        execcmd = re.sub('\${EXE}', binary, execcmd)
-        execcmd = re.sub('\$zero_buffer', "--cfg=smpi/buffering:zero", execcmd)
-        execcmd = re.sub('\$infty_buffer', "--cfg=smpi/buffering:infty", execcmd)
+            execcmd = execcmd.replace("smpirun", "smpirun --cfg=model-check/reduction:none")
+        execcmd = execcmd.replace('${EXE}', binary)
+        execcmd = execcmd.replace('$zero_buffer', "--cfg=smpi/buffering:zero")
+        execcmd = execcmd.replace('$infty_buffer', "--cfg=smpi/buffering:infty")
 
         run_cmd(
             buildcmd=f"smpicc {filename} -trace-call-location -g -Wl,-znorelro -Wl,-znoseparate-code -o {binary}",