// ================================================================== // Author: Jean-Michel Richer // Email: jean-michel.richer@univ-angers.fr // Date: Aug 2016 // Purpose: Demonstrate basic send functionality, send array of float // from master (rank=0) to slave (rank=1) // ================================================================== #include #include #include #include // for sleep using namespace std; #include // ============================================================== // C++ version // ============================================================== int main(int argc, char ** argv) { // maximum number of CPUs int max_cpus; // cpu identifier (called rank) int cpu_rank; // C-string to store name of the host char cpu_name[MPI::MAX_PROCESSOR_NAME]; // length of the C-string int length; // initialization also using command line parameters MPI::Init(argc, argv); // get number of programs running max_cpus = MPI::COMM_WORLD.Get_size(); // get program identifier cpu_rank = MPI::COMM_WORLD.Get_rank(); // get cpu name memset(cpu_name, 0, MPI::MAX_PROCESSOR_NAME); MPI::Get_processor_name(cpu_name, length); cerr << cpu_rank << "/" << max_cpus << " on machine " << cpu_name << endl; // number of elements of the array 'data' that will be allocated int data_size; // array of float created by the master and sent to the slave(s) float *data; // identifier (rank) of remove processor (master or slave) int remote_cpu; // Status for communication MPI::Status status; // MASTER if (cpu_rank == 0) { // MASTER // processor of id 0 (master) fills and sends the array data_size = 100 + rand() % 100; data = new float [data_size]; for (int i=0; i