Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
authorMartin Quinson <martin.quinson@loria.fr>
Wed, 15 Jun 2016 19:48:33 +0000 (21:48 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Wed, 15 Jun 2016 19:48:33 +0000 (21:48 +0200)
14 files changed:
examples/s4u/CMakeLists.txt
examples/s4u/mutex/.gitignore [new file with mode: 0644]
examples/s4u/mutex/s4u_mutex.cpp [new file with mode: 0644]
examples/s4u/mutex/s4u_mutex.tesh [new file with mode: 0644]
include/simgrid/s4u.h
include/simgrid/s4u/mutex.hpp [new file with mode: 0644]
src/mc/Client.cpp
src/s4u/s4u_mutex.cpp [new file with mode: 0644]
src/simix/smx_process.cpp
src/simix/smx_process_private.h
src/simix/smx_synchro_private.h
src/smpi/smpi_base.cpp
tools/cmake/DefinePackages.cmake
tools/jenkins/Flags.sh [new file with mode: 0755]

index 686defd..e90125e 100644 (file)
@@ -1,4 +1,4 @@
-foreach (example basic io)
+foreach (example basic io mutex)
   add_executable       (s4u_${example}  ${example}/s4u_${example}.cpp)
   target_link_libraries(s4u_${example}  simgrid)
   set_target_properties(s4u_${example}  PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${example})
@@ -13,3 +13,4 @@ set(txt_files     ${txt_files}    ${CMAKE_CURRENT_SOURCE_DIR}/README  PARENT_SCO
 
 ADD_TESH_FACTORIES(s4u-basic "thread;ucontext;raw;boost" --setenv bindir=${CMAKE_BINARY_DIR}/examples/s4u/basic --cd ${CMAKE_HOME_DIRECTORY}/examples/s4u/basic s4u_basic.tesh)
 ADD_TESH_FACTORIES(s4u-io    "thread;ucontext;raw;boost" --setenv bindir=${CMAKE_BINARY_DIR}/examples/s4u/io    --cd ${CMAKE_HOME_DIRECTORY}/examples/s4u/io    s4u_io.tesh)
+ADD_TESH_FACTORIES(s4u-mutex    "thread;ucontext;raw;boost" --setenv bindir=${CMAKE_BINARY_DIR}/examples/s4u/mutex    --cd ${CMAKE_HOME_DIRECTORY}/examples/s4u/mutex    s4u_mutex.tesh)
diff --git a/examples/s4u/mutex/.gitignore b/examples/s4u/mutex/.gitignore
new file mode 100644 (file)
index 0000000..0ace5ca
--- /dev/null
@@ -0,0 +1 @@
+s4u_actor
diff --git a/examples/s4u/mutex/s4u_mutex.cpp b/examples/s4u/mutex/s4u_mutex.cpp
new file mode 100644 (file)
index 0000000..f46efa9
--- /dev/null
@@ -0,0 +1,96 @@
+/* Copyright (c) 2006-2015. The SimGrid Team. All rights reserved.          */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include <xbt/sysdep.h>
+#include <mutex>
+
+#include "simgrid/s4u.h"
+
+#define NB_ACTOR 2
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "a sample log category");
+
+// simgrid::s4u::Mutex mtx; //FIXME generate error -> You must run MSG_init before using MSG
+
+//Create an actor as a c++ functor
+class Worker {
+  simgrid::s4u::Mutex mutex_;
+  int *results_;
+public:
+  Worker(int  *res, simgrid::s4u::Mutex mutex) :
+    mutex_(std::move(mutex)),  results_(res) {};
+  // Define the code of the actor
+  void operator()() {
+    // Do the calculation
+    simgrid::s4u::this_actor::execute(1000);
+
+    // lock the mutex before enter in the critical section
+    std::lock_guard<simgrid::s4u::Mutex> lock(mutex_);
+    XBT_INFO("Hello s4u, I'm ready to compute");
+
+    // And finaly add it to the results
+    *results_ += 1;
+    XBT_INFO("I'm done, good bye");
+  }
+};
+
+// This class is an example of how to use lock_guard with simgrid mutex
+class WorkerLockGuard {
+  simgrid::s4u::Mutex mutex_;
+int *results_;
+public:
+  WorkerLockGuard(int  *res, simgrid::s4u::Mutex mutex) :
+    mutex_(std::move(mutex)),  results_(res) {};
+  void operator()() {
+
+    simgrid::s4u::this_actor::execute(1000);
+
+    // Simply use the std::lock_guard like this
+    std::lock_guard<simgrid::s4u::Mutex> lock(mutex_);
+
+    // then you are in a safe zone
+    XBT_INFO("Hello s4u, I'm ready to compute");
+    // update the results
+    *results_ += 1;
+    XBT_INFO("I'm done, good bye");
+  }
+};
+
+class MainActor {
+public:
+  void operator()() {
+    int res = 0;
+    simgrid::s4u::Mutex mutex;
+    simgrid::s4u::Actor* workers[NB_ACTOR*2];
+
+    for (int i = 0; i < NB_ACTOR * 2 ; i++) {
+      // To create a worker use the static method simgrid::s4u::Actor.
+      if((i % 2) == 0 )
+        workers[i] = new simgrid::s4u::Actor("worker",
+          simgrid::s4u::Host::by_name("Jupiter"),
+          WorkerLockGuard(&res, mutex));
+      else
+        workers[i] = new simgrid::s4u::Actor("worker",
+          simgrid::s4u::Host::by_name("Tremblay"),
+          Worker(&res, mutex));
+    }
+
+    for (int i = 0; i < NB_ACTOR ; i++) {
+      delete workers[i];
+    }
+
+    simgrid::s4u::this_actor::sleep(10);
+    XBT_INFO("Results is -> %d", res);
+  }
+};
+
+
+int main(int argc, char **argv) {
+  simgrid::s4u::Engine *e = new simgrid::s4u::Engine(&argc,argv);
+  e->loadPlatform("../../platforms/two_hosts.xml");
+  new simgrid::s4u::Actor("main", simgrid::s4u::Host::by_name("Tremblay"), 0, MainActor());
+  e->run();
+  return 0;
+}
diff --git a/examples/s4u/mutex/s4u_mutex.tesh b/examples/s4u/mutex/s4u_mutex.tesh
new file mode 100644 (file)
index 0000000..e0f1040
--- /dev/null
@@ -0,0 +1,12 @@
+#! ./tesh
+
+$ $SG_TEST_EXENV ${bindir:=.}/s4u_mutex
+>[Tremblay:worker:(0) 0.000080] [s4u_test/INFO] Hello s4u, I'm ready to compute
+>[Tremblay:worker:(0) 0.000080] [s4u_test/INFO] I'm done, good bye
+>[Tremblay:worker:(0) 0.000080] [s4u_test/INFO] Hello s4u, I'm ready to compute
+>[Tremblay:worker:(0) 0.000080] [s4u_test/INFO] I'm done, good bye
+>[Jupiter:worker:(0) 0.000160] [s4u_test/INFO] Hello s4u, I'm ready to compute
+>[Jupiter:worker:(0) 0.000160] [s4u_test/INFO] I'm done, good bye
+>[Jupiter:worker:(0) 0.000160] [s4u_test/INFO] Hello s4u, I'm ready to compute
+>[Jupiter:worker:(0) 0.000160] [s4u_test/INFO] I'm done, good bye
+>[Tremblay:main:(0) 10.000000] [s4u_test/INFO] Results is -> 4
index 42cb73b..dde3205 100644 (file)
@@ -11,6 +11,7 @@
 #include "s4u/engine.hpp"
 #include "s4u/host.hpp"
 
+#include "s4u/mutex.hpp"
 #include "s4u/Activity.hpp"
 #include "s4u/comm.hpp"
 
diff --git a/include/simgrid/s4u/mutex.hpp b/include/simgrid/s4u/mutex.hpp
new file mode 100644 (file)
index 0000000..da7c3df
--- /dev/null
@@ -0,0 +1,61 @@
+/* Copyright (c) 2006-2015. The SimGrid Team. All rights reserved.          */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#ifndef SIMGRID_S4U_MUTEX_HPP
+#define SIMGRID_S4U_MUTEX_HPP
+
+#include <utility>
+
+#include <boost/intrusive_ptr.hpp>
+#include <xbt/base.h>
+#include "simgrid/simix.h"
+
+namespace simgrid {
+namespace s4u {
+
+XBT_PUBLIC_CLASS Mutex {
+
+public:
+  Mutex() :
+    mutex_(simcall_mutex_init()) {}
+  Mutex(simgrid::simix::Mutex* mutex) : mutex_(SIMIX_mutex_dup(mutex)) {}
+  ~Mutex()
+  {
+    SIMIX_mutex_destroy(mutex_);
+  }
+
+  // Copy+move (with the copy-and-swap idiom):
+  Mutex(Mutex const& mutex) : mutex_(SIMIX_mutex_dup(mutex.mutex_)) {}
+  friend void swap(Mutex& first, Mutex& second)
+  {
+    using std::swap;
+    swap(first.mutex_, second.mutex_);
+  }
+  Mutex& operator=(Mutex mutex)
+  {
+    swap(*this, mutex);
+    return *this;
+  }
+  Mutex(Mutex&& mutex) : mutex_(nullptr)
+  {
+    swap(*this, mutex);
+  }
+
+  bool valid() const
+  {
+    return mutex_ != nullptr;
+  }
+
+public:
+  void lock();
+  void unlock();
+  bool try_lock();
+
+private:
+  simgrid::simix::Mutex* mutex_;
+};
+}} // namespace simgrid::s4u
+
+#endif /* SIMGRID_S4U_MUTEX_HPP */
index cf7398d..661d404 100644 (file)
@@ -138,7 +138,9 @@ void Client::handleMessages()
         if (s != sizeof(message))
           xbt_die("Unexpected size for SIMCALL_HANDLE");
         memcpy(&message, message_buffer, sizeof(message));
+#if HAVE_SMPI
         smpi_really_switch_data_segment(message.index);
+#endif
       }
       break;
 
diff --git a/src/s4u/s4u_mutex.cpp b/src/s4u/s4u_mutex.cpp
new file mode 100644 (file)
index 0000000..e64bfd4
--- /dev/null
@@ -0,0 +1,29 @@
+/* Copyright (c) 2006-2015. The SimGrid Team.
+ * All rights reserved.                                                     */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "xbt/log.h"
+#include "src/msg/msg_private.h"
+#include "src/simix/smx_network_private.h"
+
+#include "simgrid/s4u/mutex.hpp"
+
+namespace simgrid {
+namespace s4u {
+
+void Mutex::lock() {
+  simcall_mutex_lock(mutex_);
+}
+
+void Mutex::unlock() {
+  simcall_mutex_unlock(mutex_);
+}
+
+bool Mutex::try_lock() {
+  return simcall_mutex_trylock(mutex_);
+}
+
+}
+}
index 1eb504d..b47211a 100644 (file)
@@ -126,17 +126,24 @@ void SIMIX_process_empty_trash(void)
 
   while ((process = (smx_process_t) xbt_swag_extract(simix_global->process_to_destroy))) {
     XBT_DEBUG("Getting rid of %p",process);
-    delete process->context;
-    xbt_dict_free(&process->properties);
-    xbt_fifo_free(process->comms);
-    xbt_dynar_free(&process->on_exit);
-    delete process;
+    intrusive_ptr_release(process);
   }
 }
 
 namespace simgrid {
 namespace simix {
 
+Process::~Process()
+{
+  delete this->context;
+  if (this->properties)
+    xbt_dict_free(&this->properties);
+  if (this->comms != nullptr)
+    xbt_fifo_free(this->comms);
+  if (this->on_exit)
+    xbt_dynar_free(&this->on_exit);
+}
+
 void create_maestro(std::function<void()> code)
 {
   smx_process_t maestro = nullptr;
index 0a81e9a..837cc22 100644 (file)
@@ -7,6 +7,7 @@
 #ifndef _SIMIX_PROCESS_PRIVATE_H
 #define _SIMIX_PROCESS_PRIVATE_H
 
+#include <atomic>
 #include <functional>
 #include <string>
 
@@ -68,6 +69,24 @@ public:
   std::function<void()> code;
   smx_timer_t kill_timer = nullptr;
   int segment_index      = 0;    /*Reference to an SMPI process' data segment. Default value is -1 if not in SMPI context*/
+
+  friend void intrusive_ptr_add_ref(Process* process)
+  {
+    auto previous = (process->refcount_)++;
+    xbt_assert(previous != 0);
+    (void) previous;
+  }
+  friend void intrusive_ptr_release(Process* process)
+  {
+    auto count = --(process->refcount_);
+    if (count == 0)
+      delete process;
+  }
+
+  ~Process();
+
+private:
+  std::atomic_int_fast32_t refcount_ { 1 };
 };
 
 }
index 802716a..21e76b4 100644 (file)
@@ -36,13 +36,13 @@ public:
   // boost::intrusive_ptr<Mutex> support:
   friend void intrusive_ptr_add_ref(Mutex* mutex)
   {
-    auto previous = ++mutex->refcount_;
+    auto previous = (mutex->refcount_)++;
     xbt_assert(previous != 0);
     (void) previous;
   }
   friend void intrusive_ptr_release(Mutex* mutex)
   {
-    auto count = mutex->refcount_--;
+    auto count = --(mutex->refcount_);
     if (count == 0)
       delete mutex;
   }
index ccc85cd..011c539 100644 (file)
@@ -805,7 +805,8 @@ int smpi_mpi_testany(int count, MPI_Request requests[], int *index, MPI_Status *
       nsleeps++;
     }
   } else {
-      flag = 0; // all requests are null or inactive, return false
+      //all requests are null or inactive, return true
+      flag = 1;
       smpi_empty_status(status);
   }
   xbt_dynar_free(&comms);
index eb8ef77..586f2ae 100644 (file)
@@ -381,6 +381,7 @@ set(S4U_SRC
   src/s4u/s4u_file.cpp  
   src/s4u/s4u_host.cpp  
   src/s4u/s4u_mailbox.cpp
+  src/s4u/s4u_mutex.cpp
   src/s4u/s4u_storage.cpp
 )
 
@@ -644,6 +645,7 @@ set(headers_to_install
   include/simgrid/s4u/file.hpp  
   include/simgrid/s4u/host.hpp  
   include/simgrid/s4u/mailbox.hpp  
+  include/simgrid/s4u/mutex.hpp
   include/simgrid/s4u/storage.hpp  
   include/simgrid/s4u.h
   include/simgrid/plugins/energy.h
diff --git a/tools/jenkins/Flags.sh b/tools/jenkins/Flags.sh
new file mode 100755 (executable)
index 0000000..931a135
--- /dev/null
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+set -e
+
+die() {
+    echo "$@"
+    exit 1
+}
+
+do_cleanup() {
+  for d in "$WORKSPACE/build"
+  do
+    if [ -d "$d" ]
+    then
+      rm -rf "$d" || die "Could not remote $d"
+    fi
+  done
+}
+
+### Cleanup previous runs
+
+! [ -z "$WORKSPACE" ] || die "No WORKSPACE"
+[ -d "$WORKSPACE" ] || die "WORKSPACE ($WORKSPACE) does not exist"
+
+do_cleanup
+
+for d in "$WORKSPACE/build"
+do
+  mkdir "$d" || die "Could not create $d"
+done
+
+NUMPROC="$(nproc)" || NUMPROC=1
+
+cd $WORKSPACE/build
+
+for buildjava in ON OFF
+do
+  for buildmalloc in ON OFF
+  do
+    for buildsmpi in ON OFF
+    do
+      for buildmc in ON OFF
+      do
+        echo "build with java=${buildjava}, mallocators=${buildmalloc}, SMPI=${buildsmpi}, MC=${buildmc}"
+        cmake -Denable_documentation=OFF -Denable_lua=ON -Denable_java=${buildjava} \
+              -Denable_compile_optimizations=OFF -Denable_compile_warnings=ON \
+              -Denable_jedule=ON -Denable_mallocators=${buildmalloc} \
+              -Denable_smpi=${buildsmpi} -Denable_smpi_MPICH3_testsuite=${buildsmpi} -Denable_model-checking=${buildmc} \
+              -Denable_memcheck=OFF -Denable_memcheck_xml=OFF -Denable_smpi_ISP_testsuite=OFF -Denable_coverage=OFF $WORKSPACE
+        make -j$NUMPROC
+        make clean
+      done
+    done
+  done
+done 
+