Commit 517a4e38 authored by FRIEDEMANN Sebastian's avatar FRIEDEMANN Sebastian
Browse files

Renaming

parent caebf0e5
......@@ -66,12 +66,12 @@ int getCommSize()
}
struct ServerRank
struct ServerRankConnection
{
void * data_request_socket;
ServerRank(const char * addr_request)
ServerRankConnection(const char * addr_request)
{
data_request_socket = zmq_socket (context, ZMQ_REQ);
assert(data_request_socket);
......@@ -84,7 +84,7 @@ struct ServerRank
D("connect socket %p", data_request_socket);
}
~ServerRank()
~ServerRankConnection()
{
D("closing socket %p", data_request_socket);
zmq_close(data_request_socket);
......@@ -174,9 +174,9 @@ struct Server
Server server;
struct ServerRanks {
static map<int, unique_ptr<ServerRank>> ranks;
static map<int, unique_ptr<ServerRankConnection>> ranks;
static ServerRank &get(int server_rank)
static ServerRankConnection &get(int server_rank)
{
auto found = ranks.find(server_rank);
if (found == ranks.end())
......@@ -185,7 +185,7 @@ struct ServerRanks {
// we use unique_ptr's as other wise we would create a ServerRank locally, we than would copy all its values in the ranks map
// and then we would destroy it. unfortunately this also closes the zmq connection !
auto res = ranks.emplace(server_rank,
unique_ptr<ServerRank>(new ServerRank(server.port_names.data() + server_rank * MPI_MAX_PROCESSOR_NAME)));
unique_ptr<ServerRankConnection>(new ServerRankConnection(server.port_names.data() + server_rank * MPI_MAX_PROCESSOR_NAME)));
return *res.first->second;
}
else
......@@ -194,12 +194,12 @@ struct ServerRanks {
}
}
};
map<int, unique_ptr<ServerRank>> ServerRanks::ranks;
map<int, unique_ptr<ServerRankConnection>> ServerRanks::ranks;
struct ConnectedServerRank {
size_t send_count;
size_t local_vector_offset;
ServerRank &server_rank;
ServerRankConnection &server_rank;
};
struct Field {
......@@ -422,7 +422,7 @@ void melissa_finalize() // TODO: when using more serverranks, wait until an end
MPI_Barrier(comm);
//sleep(3);
D("End Simulation.");
D("server_ranks: %lu", ServerRanks::ranks.size());
D("server ranks: %lu", ServerRanks::ranks.size());
phase = PHASE_FINAL;
// TODO: free all pointers?
......
......@@ -10,25 +10,25 @@ struct n_to_m { // TODO: rename datatype into Part
size_t send_count;
};
std::vector<n_to_m> calculate_n_to_m(int ranks_server, const std::vector<size_t> &local_vect_sizes_simu)
std::vector<n_to_m> calculate_n_to_m(const int comm_size_server, const std::vector<size_t> &local_vect_sizes_simu)
{
size_t ranks_simu = local_vect_sizes_simu.size();
size_t comm_size_simu = local_vect_sizes_simu.size();
std::vector <n_to_m> parts;
size_t local_vect_sizes_server[ranks_server];
size_t local_vect_sizes_server[comm_size_server];
size_t global_vect_size = 0;
for (size_t i = 0; i < ranks_simu; ++i)
for (size_t i = 0; i < comm_size_simu; ++i)
{
global_vect_size += local_vect_sizes_simu[i];
}
for (int i = 0; i < ranks_server; ++i)
for (int i = 0; i < comm_size_server; ++i)
{
// every server rank gets the same amount
local_vect_sizes_server[i] = global_vect_size / ranks_server;
local_vect_sizes_server[i] = global_vect_size / comm_size_server;
// let n be the rest of this division
// the first n server ranks get one more to split the rest fair up...
size_t n_rest = global_vect_size - size_t(global_vect_size / ranks_server) * ranks_server;
size_t n_rest = global_vect_size - size_t(global_vect_size / comm_size_server) * comm_size_server;
if (size_t(i) < n_rest)
{
local_vect_sizes_server[i]++;
......
......@@ -2,6 +2,7 @@
// TODO 1. refactoring
// TODO: use zmq cpp??
// TODO 2. error prone ness
// TODO: check ret values!
// TODO 3. check with real world sim and DA.
#include <map>
......@@ -56,7 +57,7 @@ struct Part
struct EnsembleMember
{
vector<double> state_analysis; // really tODO use vector! vector.data() will give the same... raw pointer!
vector<double> state_analysis;
vector<double> state_background;
size_t received_state_background = 0;
......@@ -94,7 +95,6 @@ struct Field {
ensemble_members.resize(ensemble_size_);
}
// TODO: naming: server_comm size or ranks_server? same for simu!
/// Calculates all the state vector parts that are send between the server and the
/// simulations
void calculate_parts(int server_comm_size)
......@@ -186,7 +186,7 @@ struct ConnectedSimulationRank {
/// returns true if a new was sent.
bool try_to_start_task(int simu_rank) {
bool try_send_task(int simu_rank) {
// already working?
if (current_task != WANT_WORK)
......@@ -299,9 +299,9 @@ struct Simulation // Model process runner
}
}
void try_to_start_task() {// todo: replace fields.begin() by field as there will be only on field soon.
void try_send_task() {// low: replace fields.begin() by field as there will be only on field soon.
for (auto cs = connected_simulation_ranks.begin(); cs != connected_simulation_ranks.end(); cs++) {
cs->second.try_to_start_task(cs->first);
cs->second.try_send_task(cs->first);
}
}
......@@ -671,6 +671,7 @@ int main(int argc, char * argv[])
zmq_msg_size(&data_msg), part.send_count * sizeof(double), field_name, simu_id, simu_rank, simu_state_id, simu_timestamp);
D("local server offset %lu, sendcount=%lu", part.local_offset_server, part.send_count);
D("values[0] = %.3f", reinterpret_cast<double*>(zmq_msg_data(&data_msg))[0]);
if (simu_timestamp == current_timestamp)
{
......@@ -695,7 +696,7 @@ int main(int argc, char * argv[])
zmq_msg_close(&data_msg);
// Check if we can answer directly with new data... means starting of a new model task
bool got_task = simu.connected_simulation_ranks[simu_rank].try_to_start_task(simu_rank);
bool got_task = simu.connected_simulation_ranks[simu_rank].try_send_task(simu_rank);
// If we could not start a new model task try to schedule a new one. This is initiated by server rank 0
if (!got_task && comm_rank == 0)
......@@ -704,7 +705,7 @@ int main(int argc, char * argv[])
schedule_new_task(simu_id);
// try to run it directly:
simu.connected_simulation_ranks[simu_rank].try_to_start_task(simu_rank);
simu.connected_simulation_ranks[simu_rank].try_send_task(simu_rank);
}
}
......@@ -740,7 +741,7 @@ int main(int argc, char * argv[])
{
if (schedule_new_task(simu_it->first)) {
// normally we arrive always here if there are not more model task runners than ensemble members.
simu_it->second.try_to_start_task();
simu_it->second.try_send_task();
}
}
}
......@@ -748,8 +749,6 @@ int main(int argc, char * argv[])
}
// TODO: check ret values!
// TODO: remove compile warnings!
if (phase == PHASE_SIMULATION && comm_rank != 0)
{
......@@ -766,7 +765,7 @@ int main(int argc, char * argv[])
simu.addTask(new_task.task_id, new_task.task);
// If so try to start them directly.
simu.try_to_start_task();
simu.try_send_task();
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment