Changed Allreduce to Reduce for CurrentCollector
and DeletionLogger; removed sync_ field copies
This commit is contained in:
@@ -45,6 +45,13 @@ class CpuSynchronizer {
|
|||||||
|
|
||||||
// array has to be the delta of the timestep
|
// array has to be the delta of the timestep
|
||||||
void sumToAll(blitz::Array<double, 5>& array);
|
void sumToAll(blitz::Array<double, 5>& array);
|
||||||
|
|
||||||
|
// collect data to rank 0 functions
|
||||||
|
void sumToRoot(blitz::Array<double, 3>& array);
|
||||||
|
void sumToRoot(long int& value);
|
||||||
|
void sumToRoot(double& value);
|
||||||
|
|
||||||
|
const int root = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* CPU_SYNCHRONIZER_H */
|
#endif /* CPU_SYNCHRONIZER_H */
|
||||||
|
|||||||
@@ -70,14 +70,14 @@ class CurrentCollector {
|
|||||||
blitz::Array<double, 3> r_negative_crossings;
|
blitz::Array<double, 3> r_negative_crossings;
|
||||||
blitz::Array<double, 3> r_positive_crossings;
|
blitz::Array<double, 3> r_positive_crossings;
|
||||||
|
|
||||||
blitz::Array<double, 3> sync_z_negative_crossings;
|
// blitz::Array<double, 3> sync_z_negative_crossings;
|
||||||
blitz::Array<double, 3> sync_z_positive_crossings;
|
// blitz::Array<double, 3> sync_z_positive_crossings;
|
||||||
|
|
||||||
blitz::Array<double, 3> sync_phi_negative_crossings;
|
// blitz::Array<double, 3> sync_phi_negative_crossings;
|
||||||
blitz::Array<double, 3> sync_phi_positive_crossings;
|
// blitz::Array<double, 3> sync_phi_positive_crossings;
|
||||||
|
|
||||||
blitz::Array<double, 3> sync_r_negative_crossings;
|
// blitz::Array<double, 3> sync_r_negative_crossings;
|
||||||
blitz::Array<double, 3> sync_r_positive_crossings;
|
// blitz::Array<double, 3> sync_r_positive_crossings;
|
||||||
|
|
||||||
blitz::Array<double, 3> collector_areas_r;
|
blitz::Array<double, 3> collector_areas_r;
|
||||||
blitz::Array<double, 3> collector_areas_phi;
|
blitz::Array<double, 3> collector_areas_phi;
|
||||||
|
|||||||
@@ -40,10 +40,10 @@ class DeletionLogger {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<DeletionType, long int> num_deletions;
|
std::map<DeletionType, long int> num_deletions;
|
||||||
std::map<DeletionType, long int> sync_num_deletions;
|
// std::map<DeletionType, long int> sync_num_deletions;
|
||||||
|
|
||||||
std::map<PhysicalDeletionType, double> num_phys_deletions;
|
std::map<PhysicalDeletionType, double> num_phys_deletions;
|
||||||
std::map<PhysicalDeletionType, double> sync_num_phys_deletions;
|
// std::map<PhysicalDeletionType, double> sync_num_phys_deletions;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,32 @@ void CpuSynchronizer::sumToAll(long int& value, long int& last_sync_value) {
|
|||||||
last_sync_value += delta;
|
last_sync_value += delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CpuSynchronizer::sumToRoot(blitz::Array<double, 3>& array) {
|
||||||
|
int size = array.size();
|
||||||
|
if(MpiCommunication::mpi_rank == root)
|
||||||
|
MPI_Reduce(MPI_IN_PLACE, array.data(), size, MPI_DOUBLE, MPI_SUM, root, MPI_COMM_WORLD);
|
||||||
|
else
|
||||||
|
MPI_Reduce(array.data(), nullptr, size, MPI_DOUBLE, MPI_SUM, root, MPI_COMM_WORLD);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CpuSynchronizer::sumToRoot(long int& value) {
|
||||||
|
int size = 1;
|
||||||
|
if(MpiCommunication::mpi_rank == root) {
|
||||||
|
MPI_Reduce(MPI_IN_PLACE, &value, size, MPI_LONG, MPI_SUM, root, MPI_COMM_WORLD);
|
||||||
|
} else {
|
||||||
|
MPI_Reduce(&value, nullptr, size, MPI_LONG, MPI_SUM, root, MPI_COMM_WORLD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CpuSynchronizer::sumToRoot(double& value) {
|
||||||
|
int size = 1;
|
||||||
|
if(MpiCommunication::mpi_rank == root) {
|
||||||
|
MPI_Reduce(MPI_IN_PLACE, &value, size, MPI_DOUBLE, MPI_SUM, root, MPI_COMM_WORLD);
|
||||||
|
} else {
|
||||||
|
MPI_Reduce(&value, nullptr, size, MPI_DOUBLE, MPI_SUM, root, MPI_COMM_WORLD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CpuSynchronizer::synchronize(Timer* timer, Timer* last_sync_timer) {
|
void CpuSynchronizer::synchronize(Timer* timer, Timer* last_sync_timer) {
|
||||||
if(timer == last_sync_timer) {
|
if(timer == last_sync_timer) {
|
||||||
ERROR("Synchronization of timers cannot work, point to same object.");
|
ERROR("Synchronization of timers cannot work, point to same object.");
|
||||||
@@ -92,35 +118,41 @@ void CpuSynchronizer::synchronize(DynamicDensityField* field) {
|
|||||||
|
|
||||||
void CpuSynchronizer::synchronize(CurrentCollector* collector) {
|
void CpuSynchronizer::synchronize(CurrentCollector* collector) {
|
||||||
if (collector) {
|
if (collector) {
|
||||||
sumToAll(collector->z_negative_crossings,
|
// sumToAll(collector->z_negative_crossings,
|
||||||
collector->sync_z_negative_crossings);
|
// collector->sync_z_negative_crossings);
|
||||||
collector->z_negative_crossings =
|
// collector->z_negative_crossings =
|
||||||
collector->sync_z_negative_crossings;
|
// collector->sync_z_negative_crossings;
|
||||||
|
sumToRoot(collector->z_negative_crossings);
|
||||||
|
|
||||||
sumToAll(collector->z_positive_crossings,
|
// sumToAll(collector->z_positive_crossings,
|
||||||
collector->sync_z_positive_crossings);
|
// collector->sync_z_positive_crossings);
|
||||||
collector->z_positive_crossings =
|
// collector->z_positive_crossings =
|
||||||
collector->sync_z_positive_crossings;
|
// collector->sync_z_positive_crossings;
|
||||||
|
sumToRoot(collector->z_positive_crossings);
|
||||||
|
|
||||||
sumToAll(collector->phi_negative_crossings,
|
// sumToAll(collector->phi_negative_crossings,
|
||||||
collector->sync_phi_negative_crossings);
|
// collector->sync_phi_negative_crossings);
|
||||||
collector->phi_negative_crossings =
|
// collector->phi_negative_crossings =
|
||||||
collector->sync_phi_negative_crossings;
|
// collector->sync_phi_negative_crossings;
|
||||||
|
sumToRoot(collector->phi_negative_crossings);
|
||||||
|
|
||||||
sumToAll(collector->phi_positive_crossings,
|
// sumToAll(collector->phi_positive_crossings,
|
||||||
collector->sync_phi_positive_crossings);
|
// collector->sync_phi_positive_crossings);
|
||||||
collector->phi_positive_crossings =
|
// collector->phi_positive_crossings =
|
||||||
collector->sync_phi_positive_crossings;
|
// collector->sync_phi_positive_crossings;
|
||||||
|
sumToRoot(collector->phi_positive_crossings);
|
||||||
|
|
||||||
sumToAll(collector->r_negative_crossings,
|
// sumToAll(collector->r_negative_crossings,
|
||||||
collector->sync_r_negative_crossings);
|
// collector->sync_r_negative_crossings);
|
||||||
collector->r_negative_crossings =
|
// collector->r_negative_crossings =
|
||||||
collector->sync_r_negative_crossings;
|
// collector->sync_r_negative_crossings;
|
||||||
|
sumToRoot(collector->r_negative_crossings);
|
||||||
|
|
||||||
sumToAll(collector->r_positive_crossings,
|
// sumToAll(collector->r_positive_crossings,
|
||||||
collector->sync_r_positive_crossings);
|
// collector->sync_r_positive_crossings);
|
||||||
collector->r_positive_crossings =
|
// collector->r_positive_crossings =
|
||||||
collector->sync_r_positive_crossings;
|
// collector->sync_r_positive_crossings;
|
||||||
|
sumToRoot(collector->r_positive_crossings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,21 +160,21 @@ void CpuSynchronizer::synchronize(DeletionLogger* logger) {
|
|||||||
if (logger) {
|
if (logger) {
|
||||||
for (auto& pair : logger->num_deletions) {
|
for (auto& pair : logger->num_deletions) {
|
||||||
long int num_deletion = pair.second;
|
long int num_deletion = pair.second;
|
||||||
long int last_sync_num_deletion = logger->sync_num_deletions[pair.first];
|
// long int last_sync_num_deletion = logger->sync_num_deletions[pair.first];
|
||||||
sumToAll(num_deletion, last_sync_num_deletion);
|
sumToRoot(num_deletion);//, last_sync_num_deletion
|
||||||
// last_sync_num_deletion now contains the total number of deletions
|
// last_sync_num_deletion now contains the total number of deletions
|
||||||
// across all cpus -> update the values in the objects
|
// across all cpus -> update the values in the objects
|
||||||
pair.second = last_sync_num_deletion;
|
pair.second = num_deletion; //last_sync_num_deletion;
|
||||||
logger->sync_num_deletions[pair.first] = last_sync_num_deletion;
|
// logger->sync_num_deletions[pair.first] = last_sync_num_deletion;
|
||||||
}
|
}
|
||||||
for (auto& pair : logger->num_phys_deletions) {
|
for (auto& pair : logger->num_phys_deletions) {
|
||||||
double num_deletion = pair.second;
|
double num_deletion = pair.second;
|
||||||
double last_sync_num_deletion = logger->sync_num_phys_deletions[pair.first];
|
// double last_sync_num_deletion = logger->sync_num_phys_deletions[pair.first];
|
||||||
sumToAll(num_deletion, last_sync_num_deletion);
|
sumToRoot(num_deletion);//, last_sync_num_deletion);
|
||||||
// last_sync_num_deletion now contains the total number of deletions
|
// last_sync_num_deletion now contains the total number of deletions
|
||||||
// across all cpus -> update the values in the objects
|
// across all cpus -> update the values in the objects
|
||||||
pair.second = last_sync_num_deletion;
|
pair.second = num_deletion; //last_sync_num_deletion;
|
||||||
logger->sync_num_phys_deletions[pair.first] = last_sync_num_deletion;
|
// logger->sync_num_phys_deletions[pair.first] = last_sync_num_deletion;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,13 +12,14 @@ CurrentCollector::CurrentCollector(const CylinderBinning& position_binning,
|
|||||||
collector_areas_r(createAreaRadial(position_binning)),
|
collector_areas_r(createAreaRadial(position_binning)),
|
||||||
phi_negative_crossings(createCrossingsAzimuthal(position_binning)),
|
phi_negative_crossings(createCrossingsAzimuthal(position_binning)),
|
||||||
phi_positive_crossings(createCrossingsAzimuthal(position_binning)),
|
phi_positive_crossings(createCrossingsAzimuthal(position_binning)),
|
||||||
collector_areas_phi(createAreaAzimuthal(position_binning)),
|
collector_areas_phi(createAreaAzimuthal(position_binning))//,
|
||||||
sync_z_negative_crossings(createCrossingsLongitudinal(position_binning)),
|
// sync_z_negative_crossings(createCrossingsLongitudinal(position_binning)),
|
||||||
sync_z_positive_crossings(createCrossingsLongitudinal(position_binning)),
|
// sync_z_positive_crossings(createCrossingsLongitudinal(position_binning)),
|
||||||
sync_r_negative_crossings(createCrossingsRadial(position_binning)),
|
// sync_r_negative_crossings(createCrossingsRadial(position_binning)),
|
||||||
sync_r_positive_crossings(createCrossingsRadial(position_binning)),
|
// sync_r_positive_crossings(createCrossingsRadial(position_binning)),
|
||||||
sync_phi_negative_crossings(createCrossingsAzimuthal(position_binning)),
|
// sync_phi_negative_crossings(createCrossingsAzimuthal(position_binning)),
|
||||||
sync_phi_positive_crossings(createCrossingsAzimuthal(position_binning)) {}
|
// sync_phi_positive_crossings(createCrossingsAzimuthal(position_binning))
|
||||||
|
{}
|
||||||
|
|
||||||
blitz::Array<double, 3> CurrentCollector::createAreaLongitudinal(
|
blitz::Array<double, 3> CurrentCollector::createAreaLongitudinal(
|
||||||
const CylinderBinning& position_binning) {
|
const CylinderBinning& position_binning) {
|
||||||
@@ -264,12 +265,12 @@ void CurrentCollector::resetCurrentCollector() {
|
|||||||
r_negative_crossings = 0.;
|
r_negative_crossings = 0.;
|
||||||
r_positive_crossings = 0.;
|
r_positive_crossings = 0.;
|
||||||
|
|
||||||
sync_z_negative_crossings = 0.;
|
// sync_z_negative_crossings = 0.;
|
||||||
sync_z_positive_crossings = 0.;
|
// sync_z_positive_crossings = 0.;
|
||||||
|
|
||||||
sync_phi_negative_crossings = 0.;
|
// sync_phi_negative_crossings = 0.;
|
||||||
sync_phi_positive_crossings = 0.;
|
// sync_phi_positive_crossings = 0.;
|
||||||
|
|
||||||
sync_r_negative_crossings = 0.;
|
// sync_r_negative_crossings = 0.;
|
||||||
sync_r_positive_crossings = 0.;
|
// sync_r_positive_crossings = 0.;
|
||||||
}
|
}
|
||||||
@@ -5,11 +5,11 @@ DeletionLogger::DeletionLogger(std::vector<DeletionType> used_types,
|
|||||||
std::vector<PhysicalDeletionType> used_phys_types) {
|
std::vector<PhysicalDeletionType> used_phys_types) {
|
||||||
for (auto& type : used_types) {
|
for (auto& type : used_types) {
|
||||||
num_deletions[type] = 0;
|
num_deletions[type] = 0;
|
||||||
sync_num_deletions[type] = 0;
|
// sync_num_deletions[type] = 0;
|
||||||
}
|
}
|
||||||
for (auto& type: used_phys_types) {
|
for (auto& type: used_phys_types) {
|
||||||
num_phys_deletions[type] = 0.;
|
num_phys_deletions[type] = 0.;
|
||||||
sync_num_phys_deletions[type] = 0.;
|
// sync_num_phys_deletions[type] = 0.;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,13 +53,13 @@ void DeletionLogger::resetDeletionLogger() {
|
|||||||
for(auto& pair : num_deletions) {
|
for(auto& pair : num_deletions) {
|
||||||
pair.second = 0;
|
pair.second = 0;
|
||||||
}
|
}
|
||||||
for (auto& pair : sync_num_deletions) {
|
// for (auto& pair : sync_num_deletions) {
|
||||||
pair.second = 0;
|
// pair.second = 0;
|
||||||
}
|
// }
|
||||||
for(auto& pair : num_phys_deletions) {
|
for(auto& pair : num_phys_deletions) {
|
||||||
pair.second = 0;
|
pair.second = 0;
|
||||||
}
|
}
|
||||||
for (auto& pair : sync_num_phys_deletions) {
|
// for (auto& pair : sync_num_phys_deletions) {
|
||||||
pair.second = 0;
|
// pair.second = 0;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user