Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of framagit.org:simgrid/simgrid
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 28 Jun 2022 20:13:36 +0000 (22:13 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 28 Jun 2022 20:13:49 +0000 (22:13 +0200)
examples/sthread/pthread-mutex-simple.c
examples/sthread/pthread-mutex-simple.tesh
examples/sthread/sthread-mutex-simple.c
src/kernel/EngineImpl.cpp
src/mc/remote/AppSide.cpp
src/smpi/include/private.hpp
src/smpi/internals/smpi_global.cpp
src/sthread/sthread_impl.cpp
src/xbt/xbt_main.cpp
teshsuite/s4u/issue71/issue71.cpp

index b59214f..d46d75a 100644 (file)
@@ -5,20 +5,12 @@
 
 pthread_mutex_t mutex;
 
-static void* thread1_fun(void* ignore)
+static void* thread_fun(void* val)
 {
   pthread_mutex_lock(&mutex);
   pthread_mutex_unlock(&mutex);
 
-  fprintf(stderr, "The first thread is terminating.\n");
-  return NULL;
-}
-static void* thread2_fun(void* ignore)
-{
-  pthread_mutex_lock(&mutex);
-  pthread_mutex_unlock(&mutex);
-
-  fprintf(stderr, "The second thread is terminating.\n");
+  fprintf(stderr, "The thread %d is terminating.\n", *(int*)val);
   return NULL;
 }
 
@@ -26,9 +18,11 @@ int main(int argc, char* argv[])
 {
   pthread_mutex_init(&mutex, NULL);
 
-  pthread_t thread1, thread2;
-  pthread_create(&thread1, NULL, thread1_fun, NULL);
-  pthread_create(&thread2, NULL, thread2_fun, NULL);
+  int id[2] = {0, 1};
+  pthread_t thread1;
+  pthread_t thread2;
+  pthread_create(&thread1, NULL, thread_fun, (void*)&id[0]);
+  pthread_create(&thread2, NULL, thread_fun, (void*)&id[1]);
   fprintf(stderr, "All threads are started.\n");
   pthread_join(thread1, NULL);
   pthread_join(thread2, NULL);
index 00827cb..b3bba4d 100644 (file)
@@ -1,7 +1,7 @@
 $ ./pthread-mutex-simple
 > [0.000000] [sthread/INFO] Starting the simulation.
-> The first thread is terminating.
+> The thread 0 is terminating.
 > All threads are started.
-> The second thread is terminating.
+> The thread 1 is terminating.
 > User's main is terminating.
 > [0.000000] [sthread/INFO] All threads exited. Terminating the simulation.
\ No newline at end of file
index 213fca8..3ab8267 100644 (file)
@@ -5,14 +5,7 @@
 
 sthread_mutex_t mutex;
 
-static void* thread1_fun(void* ignore)
-{
-  sthread_mutex_lock(&mutex);
-  sthread_mutex_unlock(&mutex);
-
-  return NULL;
-}
-static void* thread2_fun(void* ignore)
+static void* thread_fun(void* ignore)
 {
   sthread_mutex_lock(&mutex);
   sthread_mutex_unlock(&mutex);
@@ -24,11 +17,12 @@ int main(int argc, char* argv[])
 {
   sthread_mutex_init(&mutex, NULL);
 
-  sthread_t thread1, thread2;
-  sthread_create(&thread1, NULL, thread1_fun, NULL);
-  sthread_create(&thread2, NULL, thread2_fun, NULL);
-  // pthread_join(thread1, NULL);
-  // pthread_join(thread2, NULL);
+  sthread_t thread1;
+  sthread_t thread2;
+  sthread_create(&thread1, NULL, thread_fun, NULL);
+  sthread_create(&thread2, NULL, thread_fun, NULL);
+  sthread_join(thread1, NULL);
+  sthread_join(thread2, NULL);
   fprintf(stderr, "done\n");
 
   return 0;
index 7706219..00d0f16 100644 (file)
@@ -106,7 +106,7 @@ static void segvhandler(int signum, siginfo_t* siginfo, void* /*context*/)
   } else if (siginfo->si_signo == SIGSEGV) {
     fprintf(stderr, "Segmentation fault.\n");
 #if HAVE_SMPI
-    if (smpi_enabled() && smpi_cfg_privatization() == SmpiPrivStrategies::NONE) {
+    if (SMPI_is_inited() && smpi_cfg_privatization() == SmpiPrivStrategies::NONE) {
 #if HAVE_PRIVATIZATION
       fprintf(stderr, "Try to enable SMPI variable privatization with --cfg=smpi/privatization:yes.\n");
 #else
index 8d612f1..2d4dfbe 100644 (file)
@@ -137,8 +137,8 @@ void AppSide::handle_finalize(const s_mc_message_int_t* msg) const
     if (XBT_LOG_ISENABLED(mc_client, xbt_log_priority_debug))
       kernel::EngineImpl::get_instance()->display_all_actor_status();
 #if HAVE_SMPI
-    XBT_DEBUG("Smpi_enabled: %d", (int)smpi_enabled());
-    if (smpi_enabled())
+    XBT_DEBUG("Smpi_enabled: %d", SMPI_is_inited());
+    if (SMPI_is_inited())
       SMPI_finalize();
 #endif
   }
index 87cfe01..f92ea49 100644 (file)
@@ -95,7 +95,6 @@ XBT_PRIVATE void smpi_cleanup_op_cost_callback();
 XBT_PRIVATE void smpi_comm_null_copy_buffer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff,
                                                      size_t buff_size);
 
-XBT_PRIVATE int smpi_enabled();
 XBT_PRIVATE double smpi_mpi_wtime();
 XBT_PRIVATE void smpi_mpi_init();
 
index 3ff42f8..8b3a184 100644 (file)
@@ -213,10 +213,6 @@ void smpi_comm_null_copy_buffer_callback(simgrid::kernel::activity::CommImpl*, v
   /* nothing done in this version */
 }
 
-int smpi_enabled() {
-  return MPI_COMM_WORLD != MPI_COMM_UNINITIALIZED;
-}
-
 static void smpi_init_papi()
 {
 #if HAVE_PAPI
@@ -583,11 +579,11 @@ int smpi_main(const char* executable, int argc, char* argv[])
   return smpi_exit_status;
 }
 
-static bool smpi_inited = false;
 int SMPI_is_inited()
 {
-  return smpi_inited;
+  return MPI_COMM_WORLD != MPI_COMM_UNINITIALIZED;
 }
+
 // Called either directly from the user code, or from the code called by smpirun
 void SMPI_init(){
   smpi_init_options_internal(false);
@@ -606,7 +602,6 @@ void SMPI_init(){
   }
   smpi_init_papi();
   smpi_check_options();
-  smpi_inited = true;
 }
 
 void SMPI_finalize()
index 1780543..d3e41ae 100644 (file)
@@ -23,7 +23,7 @@
 XBT_LOG_NEW_DEFAULT_CATEGORY(sthread, "pthread intercepter");
 namespace sg4 = simgrid::s4u;
 
-static sg4::Host* lilibeth = NULL;
+static sg4::Host* lilibeth = nullptr;
 
 int sthread_main(int argc, char** argv, char** envp, int (*raw_main)(int, char**, char**))
 {
@@ -63,7 +63,7 @@ static void thread_create_wrapper(void* (*user_function)(void*), void* param)
   sthread_disable();
 }
 
-int sthread_create(unsigned long int* thread, const /*pthread_attr_t*/ void* attr, void* (*start_routine)(void*),
+int sthread_create(unsigned long int* thread, const void* /*pthread_attr_t* attr*/, void* (*start_routine)(void*),
                    void* arg)
 {
   static int TID = 0;
@@ -74,16 +74,15 @@ int sthread_create(unsigned long int* thread, const /*pthread_attr_t*/ void* att
   if (SMPI_is_inited())
     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 #endif
-  char name[100];
-  sprintf(name, "%d:%d", rank, TID);
-  sg4::ActorPtr actor = sg4::Actor::init(name, lilibeth);
+  std::string name    = simgrid::xbt::string_printf("%d:%d", rank, TID);
+  sg4::ActorPtr actor = sg4::Actor::init(name.c_str(), lilibeth);
   actor->start(thread_create_wrapper, start_routine, arg);
 
   intrusive_ptr_add_ref(actor.get());
   *thread = reinterpret_cast<unsigned long>(actor.get());
   return 0;
 }
-int sthread_join(sthread_t thread, void** retval)
+int sthread_join(sthread_t thread, void** /*retval*/)
 {
   sg4::ActorPtr actor(reinterpret_cast<sg4::Actor*>(thread));
   actor->join();
@@ -92,7 +91,7 @@ int sthread_join(sthread_t thread, void** retval)
   return 0;
 }
 
-int sthread_mutex_init(sthread_mutex_t* mutex, const /*pthread_mutexattr_t*/ void* attr)
+int sthread_mutex_init(sthread_mutex_t* mutex, const void* /*pthread_mutexattr_t* attr*/)
 {
   auto m = sg4::Mutex::create();
   intrusive_ptr_add_ref(m.get());
index 9443d05..8ee72a4 100644 (file)
@@ -56,8 +56,12 @@ int xbt_pagebits = 0;
  */
 static void xbt_preinit() XBT_ATTRIB_CONSTRUCTOR(200);
 static void xbt_postexit();
-void sthread_enable() {}  // These symbols are used from ContextSwapped in any case, but they are only useful
-void sthread_disable() {} //  when libsthread is LD_PRELOADED. In this case, sthread's implem gets used instead.
+void sthread_enable()
+{ // These symbols are used from ContextSwapped in any case, but they are only useful
+}
+void sthread_disable()
+{ //  when libsthread is LD_PRELOADED. In this case, sthread's implem gets used instead.
+}
 
 #ifdef _WIN32
 #include <windows.h>
@@ -167,4 +171,4 @@ int SMPI_is_inited()
 {
   return false;
 }
-#endif
\ No newline at end of file
+#endif
index 3952bdc..6333844 100644 (file)
@@ -36,8 +36,7 @@ int main(int argc, char* argv[])
     e.load_platform(platform_file);
     simgrid::s4u::Actor::create("actor", e.host_by_name("c1_0"), runner);
     e.run();
-  }
-  catch (simgrid::AssertionError& e) {
+  } catch (const simgrid::AssertionError& e) {
     std::cout << e.what() << "\n";
   }