A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' of framagit.org:simgrid/simgrid
[simgrid.git]
/
examples
/
smpi
/
replay_multiple_manual_deploy
/
replay_multiple_manual.cpp
diff --git
a/examples/smpi/replay_multiple_manual_deploy/replay_multiple_manual.cpp
b/examples/smpi/replay_multiple_manual_deploy/replay_multiple_manual.cpp
index
4ccbb8a
..
d736085
100644
(file)
--- a/
examples/smpi/replay_multiple_manual_deploy/replay_multiple_manual.cpp
+++ b/
examples/smpi/replay_multiple_manual_deploy/replay_multiple_manual.cpp
@@
-1,4
+1,4
@@
-/* Copyright (c) 2009-20
18
. The SimGrid Team.
+/* Copyright (c) 2009-20
21
. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
@@
-14,13
+14,14
@@
This is done to avoid SMPI actors to start at actor_id=0.
3. For each job:
1. Sleep until job's starting time is reached (if needed)
This is done to avoid SMPI actors to start at actor_id=0.
3. For each job:
1. Sleep until job's starting time is reached (if needed)
- 2. Launch the replay of the corresponding time-indepent trace.
+ 2. Launch the replay of the corresponding time-indepen
den
t trace.
3. Create inter-process noise, by spawning useless actors.
4. Wait for completion (via s4u::Engine's run method)
*/
#include <algorithm>
#include <fstream>
3. Create inter-process noise, by spawning useless actors.
4. Wait for completion (via s4u::Engine's run method)
*/
#include <algorithm>
#include <fstream>
+#include <memory>
#include <sstream>
#include <stdexcept>
#include <vector>
#include <sstream>
#include <stdexcept>
#include <vector>
@@
-47,13
+48,6
@@
struct Job {
static std::vector<simgrid::s4u::Host*> hosts;
static int noise_between_jobs;
static std::vector<simgrid::s4u::Host*> hosts;
static int noise_between_jobs;
-static bool job_comparator(const Job* j1, const Job* j2)
-{
- if (j1->starting_time == j2->starting_time)
- return j1->smpi_app_name < j2->smpi_app_name;
- return j1->starting_time < j2->starting_time;
-}
-
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 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());
@@
-65,13
+59,10
@@
static void smpi_replay_process(Job* job, simgrid::s4u::BarrierPtr barrier, int
}
// Sleeps for a given amount of time
}
// Sleeps for a given amount of time
-static int sleeper_process(int
*
param)
+static int sleeper_process(int param)
{
{
- XBT_DEBUG("Sleeping for %d seconds", *param);
- simgrid::s4u::this_actor::sleep_for(*param);
-
- delete param;
-
+ XBT_DEBUG("Sleeping for %d seconds", param);
+ simgrid::s4u::this_actor::sleep_for(param);
return 0;
}
return 0;
}
@@
-79,8
+70,7
@@
static int sleeper_process(int* param)
static void pop_some_processes(int nb_processes, simgrid::s4u::Host* host)
{
for (int i = 0; i < nb_processes; ++i) {
static void pop_some_processes(int nb_processes, simgrid::s4u::Host* host)
{
for (int i = 0; i < nb_processes; ++i) {
- int* param = new int;
- *param = i + 1;
+ int param = i + 1;
simgrid::s4u::Actor::create("meh", host, sleeper_process, param);
}
}
simgrid::s4u::Actor::create("meh", host, sleeper_process, param);
}
}
@@
-106,9
+96,9
@@
static int job_executor_process(Job* job)
}
// Executes a workload of SMPI processes
}
// Executes a workload of SMPI processes
-static int workload_executor_process(
std::vector<Job*
>* workload)
+static int workload_executor_process(
const std::vector<std::unique_ptr<Job>
>* workload)
{
{
- for (
Job*
job : *workload) {
+ for (
auto const&
job : *workload) {
// Let's wait until the job's waiting time if needed
double curr_time = simgrid::s4u::Engine::get_clock();
if (job->starting_time > curr_time) {
// Let's wait until the job's waiting time if needed
double curr_time = simgrid::s4u::Engine::get_clock();
if (job->starting_time > curr_time) {
@@
-128,7
+118,7
@@
static int workload_executor_process(std::vector<Job*>* workload)
// 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());
// 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);
+ simgrid::s4u::Actor::create(str_pname, hosts[job->allocation[0]], job_executor_process, job
.get()
);
xbt_free(str_pname);
}
xbt_free(str_pname);
}
@@
-136,11
+126,11
@@
static int workload_executor_process(std::vector<Job*>* workload)
}
// Reads jobs from a workload file and returns them
}
// Reads jobs from a workload file and returns them
-static std::vector<
Job*
> all_jobs(const std::string& workload_file)
+static std::vector<
std::unique_ptr<Job>
> all_jobs(const std::string& workload_file)
{
std::ifstream f(workload_file);
xbt_assert(f.is_open(), "Cannot open file '%s'.", workload_file.c_str());
{
std::ifstream f(workload_file);
xbt_assert(f.is_open(), "Cannot open file '%s'.", workload_file.c_str());
- std::vector<
Job*
> jobs;
+ std::vector<
std::unique_ptr<Job>
> jobs;
simgrid::xbt::Path path(workload_file);
std::string dir = path.get_dir_name();
simgrid::xbt::Path path(workload_file);
std::string dir = path.get_dir_name();
@@
-156,42
+146,42
@@
static std::vector<Job*> all_jobs(const std::string& workload_file)
std::istringstream is(line);
if (is >> app_name >> filename_unprefixed >> app_size >> starting_time >> alloc) {
try {
std::istringstream is(line);
if (is >> app_name >> filename_unprefixed >> app_size >> starting_time >> alloc) {
try {
-
Job job
;
- job
.
smpi_app_name = app_name;
- job
.
filename = dir + "/" + filename_unprefixed;
- job
.
app_size = app_size;
- job
.
starting_time = starting_time;
+
auto job = std::make_unique<Job>()
;
+ job
->
smpi_app_name = app_name;
+ job
->
filename = dir + "/" + filename_unprefixed;
+ job
->
app_size = app_size;
+ job
->
starting_time = starting_time;
std::vector<std::string> subparts;
boost::split(subparts, alloc, boost::is_any_of(","), boost::token_compress_on);
std::vector<std::string> subparts;
boost::split(subparts, alloc, boost::is_any_of(","), boost::token_compress_on);
- if ((int)subparts.size() != job
.
app_size)
+ if ((int)subparts.size() != job
->
app_size)
throw std::invalid_argument("size/alloc inconsistency");
throw std::invalid_argument("size/alloc inconsistency");
- job
.
allocation.resize(subparts.size());
+ job
->
allocation.resize(subparts.size());
for (unsigned int i = 0; i < subparts.size(); ++i)
for (unsigned int i = 0; i < subparts.size(); ++i)
- job
.
allocation[i] = stoi(subparts[i]);
+ job
->
allocation[i] = stoi(subparts[i]);
// Let's read the filename
// Let's read the filename
- std::ifstream traces_file(job
.
filename);
+ std::ifstream traces_file(job
->
filename);
if (!traces_file.is_open())
if (!traces_file.is_open())
- throw std::invalid_argument("Cannot open file " + job
.
filename);
+ throw std::invalid_argument("Cannot open file " + job
->
filename);
std::string traces_line;
while (std::getline(traces_file, traces_line)) {
boost::trim_right(traces_line);
std::string traces_line;
while (std::getline(traces_file, traces_line)) {
boost::trim_right(traces_line);
- job
.
traces_filenames.push_back(dir + "/" + traces_line);
+ job
->
traces_filenames.push_back(dir + "/" + traces_line);
}
}
- if (static_cast<int>(job
.traces_filenames.size()) < job.
app_size)
+ if (static_cast<int>(job
->traces_filenames.size()) < job->
app_size)
throw std::invalid_argument("size/tracefiles inconsistency");
throw std::invalid_argument("size/tracefiles inconsistency");
- job
.traces_filenames.resize(job.
app_size);
+ job
->traces_filenames.resize(job->
app_size);
XBT_INFO("Job read: app='%s', file='%s', size=%d, start=%d, "
"alloc='%s'",
XBT_INFO("Job read: app='%s', file='%s', size=%d, start=%d, "
"alloc='%s'",
- job
.smpi_app_name.c_str(), filename_unprefixed.c_str(), job.app_size, job.
starting_time,
+ job
->smpi_app_name.c_str(), filename_unprefixed.c_str(), job->app_size, job->
starting_time,
alloc.c_str());
alloc.c_str());
- jobs.
push_back(new Job(std::move(job)
));
+ jobs.
emplace_back(std::move(job
));
} catch (const std::invalid_argument& e) {
xbt_die("Bad line '%s' of file '%s': %s.\n", line.c_str(), workload_file.c_str(), e.what());
}
} catch (const std::invalid_argument& e) {
xbt_die("Bad line '%s' of file '%s': %s.\n", line.c_str(), workload_file.c_str(), e.what());
}
@@
-200,8
+190,11
@@
static std::vector<Job*> all_jobs(const std::string& workload_file)
// Jobs are sorted by ascending date, then by lexicographical order of their
// application names
// Jobs are sorted by ascending date, then by lexicographical order of their
// application names
- sort(jobs.begin(), jobs.end(), job_comparator);
-
+ sort(jobs.begin(), jobs.end(), [](auto const& j1, auto const& j2) {
+ if (j1->starting_time == j2->starting_time)
+ return j1->smpi_app_name < j2->smpi_app_name;
+ return j1->starting_time < j2->starting_time;
+ });
for (unsigned int i = 0; i < jobs.size(); ++i)
jobs[i]->unique_job_number = i;
for (unsigned int i = 0; i < jobs.size(); ++i)
jobs[i]->unique_job_number = i;
@@
-222,10
+215,10
@@
int main(int argc, char* argv[])
xbt_assert(hosts.size() >= 4, "The given platform should contain at least 4 hosts (found %zu).", hosts.size());
// Let's retrieve all SMPI jobs
xbt_assert(hosts.size() >= 4, "The given platform should contain at least 4 hosts (found %zu).", hosts.size());
// Let's retrieve all SMPI jobs
- std::vector<
Job*
> jobs = all_jobs(argv[2]);
+ std::vector<
std::unique_ptr<Job>
> jobs = all_jobs(argv[2]);
// Let's register them
// Let's register them
- for (
const Job*
job : jobs)
+ for (
auto const&
job : jobs)
SMPI_app_instance_register(job->smpi_app_name.c_str(), nullptr, job->app_size);
SMPI_init();
SMPI_app_instance_register(job->smpi_app_name.c_str(), nullptr, job->app_size);
SMPI_init();
@@
-246,12
+239,9
@@
int main(int argc, char* argv[])
simgrid::s4u::Actor::create("workload", hosts[0], workload_executor_process, &jobs);
e.run();
simgrid::s4u::Actor::create("workload", hosts[0], workload_executor_process, &jobs);
e.run();
- XBT_INFO("Simulation finished! Final time: %g",
e.
get_clock());
+ XBT_INFO("Simulation finished! Final time: %g",
simgrid::s4u::Engine::
get_clock());
SMPI_finalize();
SMPI_finalize();
- for (const Job* job : jobs)
- delete job;
-
return 0;
}
return 0;
}