Changed CPU synchronization from averaging to
communicating changes
This commit is contained in:
@@ -7,68 +7,123 @@
|
||||
#include "simulation/species.h"
|
||||
#include "simulation/mpi_communication.h"
|
||||
|
||||
void CpuSynchronizer::sumToAll(blitz::Array<double, 4>& array) {
|
||||
void CpuSynchronizer::sumToAll(blitz::Array<double, 4>& array,
|
||||
blitz::Array<double, 4>& last_sync_array) {
|
||||
int size = array.size();
|
||||
MPI_Allreduce(MPI_IN_PLACE, array.data(), size, MPI_DOUBLE, MPI_SUM,
|
||||
MPI_COMM_WORLD);
|
||||
array /= MpiCommunication::mpi_size;
|
||||
blitz::Array<double, 4> delta(array.extent());
|
||||
delta = array - last_sync_array;
|
||||
MPI_Allreduce(MPI_IN_PLACE, delta.data(), size, MPI_DOUBLE,
|
||||
MPI_SUM, MPI_COMM_WORLD);
|
||||
last_sync_array += delta;
|
||||
}
|
||||
|
||||
void CpuSynchronizer::sumToAll(blitz::Array<long int, 4>& array) {
|
||||
void CpuSynchronizer::sumToAll(blitz::Array<long int, 4>& array,
|
||||
blitz::Array<long int, 4>& last_sync_array) {
|
||||
int size = array.size();
|
||||
MPI_Allreduce(MPI_IN_PLACE, array.data(), size, MPI_LONG, MPI_SUM,
|
||||
MPI_COMM_WORLD);
|
||||
blitz::Array<long int, 4> delta(array.extent());
|
||||
delta = array - last_sync_array;
|
||||
MPI_Allreduce(MPI_IN_PLACE, delta.data(), size, MPI_LONG,
|
||||
MPI_SUM, MPI_COMM_WORLD);
|
||||
last_sync_array += delta;
|
||||
}
|
||||
|
||||
void CpuSynchronizer::sumToAll(blitz::Array<double, 3>& array) {
|
||||
void CpuSynchronizer::sumToAll(blitz::Array<double, 3>& array,
|
||||
blitz::Array<double, 3>& last_sync_array) {
|
||||
int size = array.size();
|
||||
MPI_Allreduce(MPI_IN_PLACE, array.data(), size, MPI_DOUBLE, MPI_SUM,
|
||||
MPI_COMM_WORLD);
|
||||
array /= MpiCommunication::mpi_size;
|
||||
blitz::Array<double, 3> delta(array.extent());
|
||||
delta = array - last_sync_array;
|
||||
MPI_Allreduce(MPI_IN_PLACE, delta.data(), size, MPI_DOUBLE,
|
||||
MPI_SUM, MPI_COMM_WORLD);
|
||||
last_sync_array += delta;
|
||||
}
|
||||
|
||||
void CpuSynchronizer::sumToAll(double& value) {
|
||||
void CpuSynchronizer::sumToAll(double& value, double& last_sync_value) {
|
||||
int size = 1;
|
||||
MPI_Allreduce(MPI_IN_PLACE, &value, size, MPI_DOUBLE, MPI_SUM,
|
||||
double delta = value - last_sync_value;
|
||||
MPI_Allreduce(MPI_IN_PLACE, &delta, size, MPI_DOUBLE, MPI_SUM,
|
||||
MPI_COMM_WORLD);
|
||||
value /= MpiCommunication::mpi_size;
|
||||
last_sync_value += delta;
|
||||
}
|
||||
|
||||
void CpuSynchronizer::sumToAll(long int& value) {
|
||||
void CpuSynchronizer::sumToAll(long int& value, long int& last_sync_value) {
|
||||
int size = 1;
|
||||
MPI_Allreduce(MPI_IN_PLACE, &value, size, MPI_LONG, MPI_SUM, MPI_COMM_WORLD);
|
||||
long int delta = value - last_sync_value;
|
||||
MPI_Allreduce(MPI_IN_PLACE, &delta, size, MPI_LONG, MPI_SUM,
|
||||
MPI_COMM_WORLD);
|
||||
last_sync_value += delta;
|
||||
}
|
||||
|
||||
void CpuSynchronizer::synchronize(Timer* timer) {
|
||||
void CpuSynchronizer::synchronize(Timer* timer, Timer* last_sync_timer) {
|
||||
if(timer == last_sync_timer) {
|
||||
ERROR("Synchronization of timers cannot work, point to same object");
|
||||
}
|
||||
double time_s = timer->time();
|
||||
sumToAll(time_s);
|
||||
timer->setTime(time_s);
|
||||
double last_sync_time_s = last_sync_timer->time();
|
||||
sumToAll(time_s, last_sync_time_s);
|
||||
timer->setTime(last_sync_time_s);
|
||||
last_sync_timer->setTime(last_sync_time_s);
|
||||
}
|
||||
|
||||
void CpuSynchronizer::synchronize(DynamicDensityField* field) {
|
||||
if (field) {
|
||||
sumToAll(field->time_in_bin_s_);
|
||||
sumToAll(field->deleted_particles_);
|
||||
void CpuSynchronizer::synchronize(DynamicDensityField* field,
|
||||
DynamicDensityField* last_sync_field) {
|
||||
if (field && last_sync_field) {
|
||||
if(field == last_sync_field) {
|
||||
ERROR("The way last_sync_field is created does not work as intended.");
|
||||
}
|
||||
sumToAll(field->time_in_bin_s_, last_sync_field->time_in_bin_s_);
|
||||
field->time_in_bin_s_ = last_sync_field->time_in_bin_s_;
|
||||
|
||||
sumToAll(field->deleted_particles_, last_sync_field->deleted_particles_);
|
||||
field->deleted_particles_ = last_sync_field->deleted_particles_;
|
||||
}
|
||||
}
|
||||
|
||||
void CpuSynchronizer::synchronize(CurrentCollector* collector) {
|
||||
if (collector) {
|
||||
sumToAll(collector->z_negative_crossings);
|
||||
sumToAll(collector->z_positive_crossings);
|
||||
sumToAll(collector->phi_negative_crossings);
|
||||
sumToAll(collector->phi_positive_crossings);
|
||||
sumToAll(collector->r_negative_crossings);
|
||||
sumToAll(collector->r_positive_crossings);
|
||||
void CpuSynchronizer::synchronize(CurrentCollector* collector,
|
||||
CurrentCollector* last_sync_collector) {
|
||||
if (collector && last_sync_collector) {
|
||||
sumToAll(collector->z_negative_crossings,
|
||||
last_sync_collector->z_negative_crossings);
|
||||
collector->z_negative_crossings =
|
||||
last_sync_collector->z_negative_crossings;
|
||||
|
||||
sumToAll(collector->z_positive_crossings,
|
||||
last_sync_collector->z_positive_crossings);
|
||||
collector->z_positive_crossings =
|
||||
last_sync_collector->z_positive_crossings;
|
||||
|
||||
sumToAll(collector->phi_negative_crossings,
|
||||
last_sync_collector->phi_negative_crossings);
|
||||
collector->phi_negative_crossings =
|
||||
last_sync_collector->phi_negative_crossings;
|
||||
|
||||
sumToAll(collector->phi_positive_crossings,
|
||||
last_sync_collector->phi_positive_crossings);
|
||||
collector->phi_positive_crossings =
|
||||
last_sync_collector->phi_positive_crossings;
|
||||
|
||||
sumToAll(collector->r_negative_crossings,
|
||||
last_sync_collector->r_negative_crossings);
|
||||
collector->r_negative_crossings =
|
||||
last_sync_collector->r_negative_crossings;
|
||||
|
||||
sumToAll(collector->r_positive_crossings,
|
||||
last_sync_collector->r_positive_crossings);
|
||||
collector->r_positive_crossings =
|
||||
last_sync_collector->r_positive_crossings;
|
||||
}
|
||||
}
|
||||
|
||||
void CpuSynchronizer::synchronize(DeletionLogger* logger) {
|
||||
if (logger) {
|
||||
void CpuSynchronizer::synchronize(DeletionLogger* logger,
|
||||
DeletionLogger* last_sync_logger) {
|
||||
if (logger && last_sync_logger) {
|
||||
for (auto& pair : logger->num_deletions) {
|
||||
long int num_deletion = pair.second;
|
||||
sumToAll(num_deletion);
|
||||
pair.second = num_deletion;
|
||||
long int last_sync_num_deletion = last_sync_logger->num_deletions[pair.first];
|
||||
sumToAll(num_deletion, last_sync_num_deletion);
|
||||
// last_sync_num_deletion now contains the total number of deletions
|
||||
// across all cpus -> update the values in the objects
|
||||
pair.second = last_sync_num_deletion;
|
||||
last_sync_logger->num_deletions[pair.first] = last_sync_num_deletion;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,11 +133,19 @@ void CpuSynchronizer::synchronize(
|
||||
tracked_species) {
|
||||
MPI_Barrier(MPI_COMM_WORLD);
|
||||
auto it = tracked_species.begin();
|
||||
synchronize(it->second->dynamicDensityField()->timer_.get());
|
||||
DEBUG_LEVEL_3("Timer Synchronization.");
|
||||
synchronize(it->second->dynamicDensityField()->timer_.get(),
|
||||
it->second->lastSyncDensityField()->timer_.get());
|
||||
|
||||
for (auto& pair : tracked_species) {
|
||||
synchronize(pair.second->dynamicDensityField());
|
||||
synchronize(pair.second->currentCollector());
|
||||
synchronize(pair.second->deletionLogger());
|
||||
// DEBUG_LEVEL_3("dynden Synchronization.");
|
||||
synchronize(pair.second->dynamicDensityField(),
|
||||
pair.second->lastSyncDensityField());
|
||||
// DEBUG_LEVEL_3("cc Synchronization.");
|
||||
synchronize(pair.second->currentCollector(),
|
||||
pair.second->lastSyncCurrentCollector());
|
||||
// DEBUG_LEVEL_3("dellogger Synchronization.");
|
||||
synchronize(pair.second->deletionLogger(),
|
||||
pair.second->lastSyncDeletionLogger());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user