// ================================================================== // Author: Jean-Michel Richer // Email: jean-michel.richer@univ-angers.fr // Date: Aug 2020 // Last modified: September 2026 // Purpose: Demonstrate basic reduce functionality by computing the // sum of a floatting point values on each process // ================================================================== #include #include // for sleep #include #include #include using namespace std; #include "./ezmpi.hpp" using namespace ez::mpi; /** * run master and slaves */ void run(int argc, char* argv[]) { Process process(argc, argv); process.verbose(false); float local_data = process.id() + 1; process << "- local data=" << local_data << endl; float reduction = 0; // reduction must be performed outside the master and slaves process.reduce(local_data, reduction, MPI::SUM); // only the master will report the result if (process.is_master()) { cout << "reduction = " << reduction << endl; } process.logs(cout); } // ============================================================== // version C++ // ============================================================== int main(int argc, char** argv) { // call a function that contains the code for the master and // the slaves in order to avoid problems of initialization and // finalization of processes run(argc, argv); exit(EXIT_SUCCESS); }