XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "a sample log category");
namespace sg4 = simgrid::s4u;
-std::string data;
-bool done = false;
-
-static void worker_fun(sg4::ConditionVariablePtr cv, sg4::MutexPtr mutex)
+static void worker_fun(sg4::ConditionVariablePtr cv, sg4::MutexPtr mutex, std::string& data, bool& done)
{
std::unique_lock lock(*mutex);
{
auto mutex = sg4::Mutex::create();
auto cv = sg4::ConditionVariable::create();
- data = "Example data";
- auto worker = sg4::Actor::create("worker", sg4::Host::by_name("Jupiter"), worker_fun, cv, mutex);
+ std::string data = "Example data";
+ bool done = false;
+
+ auto worker = sg4::Actor::create("worker", sg4::Host::by_name("Jupiter"), worker_fun, cv, mutex, std::ref(data),
+ std::ref(done));
// wait for the worker
- cv->wait(std::unique_lock<sg4::Mutex>(*mutex), []() { return done; });
+ cv->wait(std::unique_lock<sg4::Mutex>(*mutex), [&done]() { return done; });
XBT_INFO("data is now '%s'.", data.c_str());
worker->join();
args is a strings array containing the blank-separated parameters found in the trace for this event instance. */
}
-action_fun previous_send;
-static void overriding_send(simgrid::xbt::ReplayAction& args)
-{
- previous_send(args); // Just call the overridden symbol. That's a toy example.
-}
-
int main(int argc, char* argv[])
{
auto properties = simgrid::s4u::Actor::self()->get_properties();
/* Connect your callback function to the "blah" event in the trace files */
xbt_replay_action_register("blah", action_blah);
- /* The send action is an override, so we have to first save its previous value in a global */
+ /* The send action is an override, so we could have saved its previous value in a global, or use a lambda capture like
+ * in the following */
int new_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &new_rank);
if (new_rank != rank)
XBT_WARN("Rank inconsistency. Got %d, expected %d", new_rank, rank);
if (rank == 0) {
- previous_send = xbt_replay_action_get("send");
- xbt_replay_action_register("send", overriding_send);
+ auto previous_send = xbt_replay_action_get("send");
+ xbt_replay_action_register("send", [previous_send](simgrid::xbt::ReplayAction& args) {
+ previous_send(args); // Just call the overridden symbol. That's a toy example.
+ });
}
/* The regular run of the replayer */
if (shared_trace != nullptr)
int unique_job_number; //!< The job unique number in [0, n[.
};
-// ugly globals to avoid creating structures for giving args to processes
-static std::vector<simgrid::s4u::Host*> hosts;
-
static void smpi_replay_process(Job* job, simgrid::s4u::BarrierPtr barrier, int rank)
{
XBT_INFO("Replaying rank %d of job %d (smpi_app '%s')", rank, job->unique_job_number, job->smpi_app_name.c_str());
}
}
-static int job_executor_process(Job* job)
+static int job_executor_process(const std::vector<simgrid::s4u::Host*>& hosts, Job* job)
{
XBT_INFO("Executing job %d (smpi_app '%s')", job->unique_job_number, job->smpi_app_name.c_str());
}
// Executes a workload of SMPI processes
-static int workload_executor_process(const std::vector<std::unique_ptr<Job>>& workload, int noise_between_jobs)
+static int workload_executor_process(const std::vector<simgrid::s4u::Host*>& hosts,
+ const std::vector<std::unique_ptr<Job>>& workload, int noise_between_jobs)
{
for (auto const& job : workload) {
// Let's wait until the job's waiting time if needed
// Let's finally run the job executor
char* str_pname = bprintf("job_%04d", job->unique_job_number);
XBT_INFO("Launching the job executor of job %d (app '%s')", job->unique_job_number, job->smpi_app_name.c_str());
- simgrid::s4u::Actor::create(str_pname, hosts[job->allocation[0]], job_executor_process, job.get());
+ simgrid::s4u::Actor::create(str_pname, hosts[job->allocation[0]], job_executor_process, std::cref(hosts),
+ job.get());
xbt_free(str_pname);
}
// Simulation setting
simgrid::s4u::Engine e(&argc, argv);
e.load_platform(argv[1]);
- hosts = e.get_all_hosts();
+ const auto hosts = e.get_all_hosts();
xbt_assert(hosts.size() >= 4, "The given platform should contain at least 4 hosts (found %zu).", hosts.size());
// Let's retrieve all SMPI jobs
}
// Let's execute the workload
- simgrid::s4u::Actor::create("workload", hosts[0], workload_executor_process, std::cref(jobs), noise_between_jobs);
+ simgrid::s4u::Actor::create("workload", hosts[0], workload_executor_process, std::cref(hosts), std::cref(jobs),
+ noise_between_jobs);
e.run();
XBT_INFO("Simulation finished! Final time: %g", simgrid::s4u::Engine::get_clock());
class XBT_PUBLIC FileDescriptorHostExt {
public:
static simgrid::xbt::Extension<Host, FileDescriptorHostExt> EXTENSION_ID;
+ static int max_file_descriptors;
FileDescriptorHostExt() = default;
FileDescriptorHostExt(const FileDescriptorHostExt&) = delete;
FileDescriptorHostExt& operator=(const FileDescriptorHostExt&) = delete;
#include "src/kernel/resource/NetworkModelFactors.hpp"
#include "simgrid/sg_config.hpp"
-#include "src/kernel/resource/FactorSet.hpp"
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_network);
*********/
namespace simgrid::kernel::resource {
-static FactorSet cfg_latency_factor("network/latency-factor");
-static FactorSet cfg_bandwidth_factor("network/bandwidth-factor");
-
config::Flag<std::string> cfg_latency_factor_str(
"network/latency-factor", std::initializer_list<const char*>{"smpi/lat-factor"},
"Correction factor to apply to the provided latency (default value overridden by network model)", "1.0");
"network/bandwidth-factor", std::initializer_list<const char*>{"smpi/bw-factor"},
"Correction factor to apply to the provided bandwidth (default value overridden by network model)", "1.0");
+FactorSet NetworkModelFactors::cfg_latency_factor("network/latency-factor");
+FactorSet NetworkModelFactors::cfg_bandwidth_factor("network/bandwidth-factor");
+
double NetworkModelFactors::get_bandwidth_factor() const
{
xbt_assert(not bw_factor_cb_,
#define SIMGRID_KERNEL_RESOURCE_NETWORKMODELFACTORS_HPP
#include "simgrid/sg_config.hpp"
+#include "src/kernel/resource/FactorSet.hpp"
#include "xbt/asserts.h"
#include <simgrid/forward.h>
/** This Trait of NetworkModel is in charge of handling the network factors (bw and lat) */
class XBT_PUBLIC NetworkModelFactors {
+ static FactorSet cfg_latency_factor;
+ static FactorSet cfg_bandwidth_factor;
+
using NetworkFactorCb = double(double size, const s4u::Host* src, const s4u::Host* dst,
const std::vector<s4u::Link*>& links,
const std::unordered_set<s4u::NetZone*>& netzones);
#include <numeric>
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_file, s4u, "S4U files");
-int sg_storage_max_file_descriptors = 1024;
/** @defgroup plugin_filesystem Plugin FileSystem
*
namespace s4u {
simgrid::xbt::Extension<Disk, FileSystemDiskExt> FileSystemDiskExt::EXTENSION_ID;
simgrid::xbt::Extension<Host, FileDescriptorHostExt> FileDescriptorHostExt::EXTENSION_ID;
+int FileDescriptorHostExt::max_file_descriptors;
const Disk* File::find_local_disk_on(const Host* host)
{
local_disk_ = find_local_disk_on(host);
// assign a file descriptor id to the newly opened File
- auto* ext = host->extension<simgrid::s4u::FileDescriptorHostExt>();
+ auto* ext = host->extension<FileDescriptorHostExt>();
if (ext->file_descriptor_table == nullptr) {
- ext->file_descriptor_table = std::make_unique<std::vector<int>>(sg_storage_max_file_descriptors);
+ ext->file_descriptor_table = std::make_unique<std::vector<int>>(FileDescriptorHostExt::max_file_descriptors);
std::iota(ext->file_descriptor_table->rbegin(), ext->file_descriptor_table->rend(), 0); // Fill with ..., 1, 0.
}
xbt_assert(not ext->file_descriptor_table->empty(), "Too much files are opened! Some have to be closed.");
void File::close()
{
- std::vector<int>* desc_table =
- Host::current()->extension<simgrid::s4u::FileDescriptorHostExt>()->file_descriptor_table.get();
+ std::vector<int>* desc_table = Host::current()->extension<FileDescriptorHostExt>()->file_descriptor_table.get();
kernel::actor::simcall_answered([this, desc_table] { desc_table->push_back(this->desc_id); });
delete this;
}
*/
void sg_storage_file_system_init()
{
- sg_storage_max_file_descriptors = 1024;
- simgrid::config::bind_flag(sg_storage_max_file_descriptors, "storage/max_file_descriptors",
+ FileDescriptorHostExt::max_file_descriptors = 1024;
+ simgrid::config::bind_flag(FileDescriptorHostExt::max_file_descriptors, "storage/max_file_descriptors",
"Maximum number of concurrently opened files per host. Default is 1024");
if (not FileSystemDiskExt::EXTENSION_ID.valid()) {