Stride Reference Manual  1.0
RemoteSimulatorSender.cpp
Go to the documentation of this file.
2 #include "SimulatorStatus.h"
3 
4 using namespace stride;
5 using namespace std;
6 
7 RemoteSimulatorSender::RemoteSimulatorSender(const string& name, const int remote_id)
8  : m_count(1), m_id_mpi(remote_id), m_name(name) {}
9 
10 future<SimulatorStatus> RemoteSimulatorSender::timeStep() {
11  std::cout << "Timestep @ RemoteSimulatorSender" << std::endl;
12  return async([&]() {
13  int tag = 4; // Tag 4 = the remote simulator must execute a timestep and we need to wait until it's done
14  SimulatorStatus data {0, 0};
15  std::cout << "Sending message to remote sim @process " << m_id_mpi << std::endl;
16  MPI_Send(nullptr, 0, MPI_INT, m_id_mpi, tag, MPI_COMM_WORLD);
17  MPI_Recv(&data, m_count, m_simulator_status, m_id_mpi, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
18  std::cout << "Received message from remote sim @process " << m_id_mpi << std::endl;
19  return data;
20  });
21 }
22 
23 void RemoteSimulatorSender::welcomeHomeTravellers(const pair<vector<uint>, vector<Health>>& travellers) {
24  int tag = 5;
25  ReturnData data {travellers};
26  MPI_Send(&data, m_count, MPI_INT, m_id_mpi, tag, MPI_COMM_WORLD);
27 }
28 
29 void RemoteSimulatorSender::hostForeignTravellers(const vector<stride::Simulator::TravellerType>& travellers, uint days,
30  const string& destination_district,
31  const string& destination_facility) {
32  int tag = 7;
33  uint amount = travellers.size();
34  TravelData data {travellers, amount, days, m_name, destination_district, destination_facility};
35  MPI_Send(&data, m_count, MPI_INT, m_id_mpi, tag, MPI_COMM_WORLD);
36 }
37 
38 // usually called by the Coordinator
39 void RemoteSimulatorSender::sendNewTravellers(uint amount, uint days, const string& destination_sim_id,
40  const string& destination_district, const string& destination_facility) {
41  int tag = 3; // Tag of the message (Tag 3 = travellers going to a region issued by the Coordinator)
42  std::vector<Simulator::TravellerType> travellers; // Empty vector
43  // TODO replace m_id with destination_sim_id?
44  TravelData data {travellers, amount, days, m_name, destination_district, destination_facility};
45  MPI_Send(&data, m_count, MPI_INT, m_id_mpi, tag, MPI_COMM_WORLD);
46 }
47 
49  int tag = 6;
50  MPI_Send(nullptr, 0, MPI_INT, m_id_mpi, tag, MPI_COMM_WORLD);
51 }
52 
53 // called by the Simulator
54 void RemoteSimulatorSender::sendNewTravellers(const vector<Simulator::TravellerType>& travellers, uint days,
55  const string& destination_sim_id, const string& destination_district,
56  const string& destination_facility) {
57  int tag = 1; // Tag of the message (Tag 1 = new travellers going to a region)
58  uint amount = travellers.size();
59  // TODO replace m_id with destination_sim_id?
60  TravelData data {travellers, amount, days, m_name, destination_district, destination_facility};
61  MPI_Send(&data, m_count, MPI_INT, m_id_mpi, tag, MPI_COMM_WORLD);
62 }
63 
64 void RemoteSimulatorSender::returnForeignTravellers(const pair<vector<uint>, vector<Health>>& travellers,
65  const string& home_sim_id) {
66  int tag = 2; // Tag of the message (Tag 2 = travellers returning home)
67  ReturnData data {travellers};
68  MPI_Send(&data, m_count, MPI_INT, m_id_mpi, tag, MPI_COMM_WORLD);
69 }
70 
72  MPI_Datatype type[2] = {MPI_INT, MPI_INT};
74  int blocklen[2] = {1, 1};
76  MPI_Aint disp[2];
77  disp[0] = offsetof(SimulatorStatus, infected);
78  disp[1] = offsetof(SimulatorStatus, adopted);
80  MPI_Type_create_struct(2, blocklen, disp, type, &m_simulator_status);
81  MPI_Type_commit(&m_simulator_status);
82 }
unsigned int uint
Definition: Influence.h:17
virtual void hostForeignTravellers(const vector< stride::Simulator::TravellerType > &travellers, uint days, const string &destination_district, const string &destination_facility) override
Receive travellers travellers: the travellers this simulator has to host.
virtual future< SimulatorStatus > timeStep() override
Time Dependent Person DataType.
Definition: NoBehaviour.h:17
virtual void sendNewTravellers(uint amount, uint days, const string &destination_sim_id, const string &destination_district, const string &destination_facility) override
Commands to send an amount of travellers to another region The Simulator will have to take action...
virtual void welcomeHomeTravellers(const pair< vector< uint >, vector< Health >> &travellers) override
RemoteSimulatorSender(const string &m_name, const int mpi_id)
STL namespace.
virtual void returnForeignTravellers() override
Return foreign people that would return today, signals the Simulator to return today&#39;s travellers...