#include "src/internal_config.h"
#include "src/sthread/sthread.h"
+#include <cmath>
#include <dlfcn.h>
#include <pthread.h>
#include <semaphore.h>
int sthread_main(int argc, char** argv, char** envp, int (*raw_main)(int, char**, char**))
{
+ /* Do not intercept the main when run from SMPI: it will initialize the simulation properly */
+ for (int i = 0; envp[i] != nullptr; i++)
+ if (strncmp(envp[i], "SMPI_GLOBAL_SIZE", strlen("SMPI_GLOBAL_SIZE")) == 0)
+ return raw_main(argc, argv, envp);
+
+ /* If not in SMPI, the old main becomes an actor in a newly created simulation */
std::ostringstream id;
id << std::this_thread::get_id();
- XBT_INFO("sthread main() is starting in thread %s", id.str().c_str());
+ XBT_DEBUG("sthread main() is starting in thread %s", id.str().c_str());
sg4::Engine e(&argc, argv);
auto* zone = sg4::create_full_zone("world");
sthread_enable();
sg4::ActorPtr main_actor = sg4::Actor::create("tid 0", lilibeth, raw_main, argc, argv, envp);
- XBT_INFO("sthread main() is launching the simulation");
+ XBT_INFO("Starting the simulation.");
sg4::Engine::get_instance()->run();
+ sthread_disable();
+ XBT_INFO("All threads exited. Terminating the simulation.");
return 0;
}
{
static int TID = 0;
TID++;
- XBT_INFO("Create thread %d", TID);
+ XBT_VERB("Create thread %d", TID);
int rank = 0;
#if HAVE_SMPI
if (SMPI_is_inited())
return 0;
}
+int sthread_gettimeofday(struct timeval* tv)
+{
+ if (tv) {
+ double now = simgrid::s4u::Engine::get_clock();
+ double secs = trunc(now);
+ double usecs = (now - secs) * 1e6;
+ tv->tv_sec = static_cast<time_t>(secs);
+ tv->tv_usec = static_cast<decltype(tv->tv_usec)>(usecs); // suseconds_t (or useconds_t on WIN32)
+ }
+ return 0;
+}
+
+void sthread_sleep(double seconds)
+{
+ simgrid::s4u::this_actor::sleep_for(seconds);
+}
+
#if 0
int sem_init(sem_t *sem, int pshared, unsigned int value) {
int res;
return raw_sem_post(sem);
}
-int pthread_join(pthread_t thread, void **retval) {
- sg_actor_join(thread, -1);
- return 0;
-}
-
int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *cond_attr) {
*cond = sg_cond_init();
return 0;