Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
extend C API for asynchronous executions
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 19 Feb 2020 14:35:41 +0000 (15:35 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 19 Feb 2020 14:35:41 +0000 (15:35 +0100)
include/simgrid/actor.h
include/simgrid/exec.h [new file with mode: 0644]
src/s4u/s4u_Actor.cpp
src/s4u/s4u_Exec.cpp
tools/cmake/DefinePackages.cmake

index 63b544f..b5de5fd 100644 (file)
@@ -70,6 +70,8 @@ XBT_PUBLIC void sg_actor_unref(const_sg_actor_t actor);
 XBT_PUBLIC void* sg_actor_data(const_sg_actor_t actor);
 XBT_PUBLIC void sg_actor_data_set(sg_actor_t actor, void* userdata);
 
+XBT_PUBLIC sg_exec_t sg_actor_exec_init(double computation_amount);
+XBT_PUBLIC sg_exec_t sg_actor_exec_async(double computation_amount);
 SG_END_DECL
 
 #endif /* INCLUDE_SIMGRID_ACTOR_H_ */
diff --git a/include/simgrid/exec.h b/include/simgrid/exec.h
new file mode 100644 (file)
index 0000000..17e7ae9
--- /dev/null
@@ -0,0 +1,24 @@
+/* Copyright (c) 2018-2020. 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 INCLUDE_SIMGRID_EXEC_H_
+#define INCLUDE_SIMGRID_EXEC_H_
+
+#include <simgrid/forward.h>
+#include <xbt/dynar.h>
+
+/* C interface */
+SG_BEGIN_DECL
+
+XBT_PUBLIC void sg_exec_set_bound(sg_exec_t exec, double bound);
+XBT_PUBLIC double sg_exec_get_remaining(sg_exec_t exec);
+
+XBT_PUBLIC void sg_exec_start(sg_exec_t exec);
+XBT_PUBLIC void sg_exec_wait(sg_exec_t exec);
+XBT_PUBLIC void sg_exec_wait_for(sg_exec_t exec, double timeout);
+
+SG_END_DECL
+
+#endif /* INCLUDE_SIMGRID_COMM_H_ */
index 6ab12ac..e230a33 100644 (file)
@@ -773,3 +773,17 @@ void sg_actor_on_exit(int_f_int_pvoid_t fun, void* data)
 {
   simgrid::s4u::this_actor::on_exit([fun, data](bool failed) { fun(failed ? 1 /*FAILURE*/ : 0 /*SUCCESS*/, data); });
 }
+
+sg_exec_t sg_actor_exec_init(double computation_amount)
+{
+  simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(computation_amount);
+  exec->add_ref();
+  return exec.get();
+}
+
+sg_exec_t sg_actor_exec_async(double computation_amount)
+{
+  simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_async(computation_amount);
+  exec->add_ref();
+  return exec.get();
+}
index ca551bf..6d629ed 100644 (file)
@@ -3,6 +3,7 @@
 /* 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 "simgrid/exec.h"
 #include "simgrid/s4u/Actor.hpp"
 #include "simgrid/s4u/Exec.hpp"
 #include "src/kernel/activity/ExecImpl.hpp"
@@ -209,3 +210,30 @@ double Exec::get_remaining_ratio() const
 
 } // namespace s4u
 } // namespace simgrid
+/* **************************** Public C interface *************************** */
+void sg_exec_set_bound(sg_exec_t exec, double bound)
+{
+  exec->set_bound(bound);
+}
+
+double sg_exec_get_remaining(sg_exec_t exec)
+{
+  return exec->get_remaining();
+}
+
+void sg_exec_start(sg_exec_t exec)
+{
+  exec->start();
+}
+
+void sg_exec_wait(sg_exec_t exec)
+{
+  exec->wait_for(-1);
+  exec->unref();
+}
+
+void sg_exec_wait_for(sg_exec_t exec, double timeout)
+{
+  exec->wait_for(timeout);
+  exec->unref();
+}
index 7b922bc..2b827e9 100644 (file)
@@ -680,6 +680,7 @@ set(headers_to_install
   include/simgrid/barrier.h
   include/simgrid/comm.h
   include/simgrid/engine.h
+  include/simgrid/exec.h
   include/simgrid/Exception.hpp
   include/simgrid/chrono.hpp
   include/simgrid/plugins/dvfs.h