// An example parallel program using MPI
#include <iostream>
#include <sstream>
#include "mpi.h"
int main(int argc, char *argv[]) {
// Initialize MPI
MPI_Init(&argc, &argv);
// Get the total number of tasks
int num_tasks;
MPI_Comm_size(MPI_COMM_WORLD, &num_tasks);
// Get the task ID
int task_id;
MPI_Comm_rank(MPI_COMM_WORLD, &task_id);
// Set up the string and print
std::stringstream ss;
ss << "Printing from task " << task_id << '/' << num_tasks << '\n';
std::cout << ss.str();
// Finish our MPI work
MPI_Finalize();
return 0;
}
Ly8gQW4gZXhhbXBsZSBwYXJhbGxlbCBwcm9ncmFtIHVzaW5nIE1QSQoKCiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHNzdHJlYW0+CgojaW5jbHVkZSAibXBpLmgiCgppbnQgbWFpbihpbnQgYXJnYywgY2hhciAqYXJndltdKSB7CiAgLy8gSW5pdGlhbGl6ZSBNUEkKICBNUElfSW5pdCgmYXJnYywgJmFyZ3YpOwoKICAvLyBHZXQgdGhlIHRvdGFsIG51bWJlciBvZiB0YXNrcwogIGludCBudW1fdGFza3M7CiAgTVBJX0NvbW1fc2l6ZShNUElfQ09NTV9XT1JMRCwgJm51bV90YXNrcyk7CgogIC8vIEdldCB0aGUgdGFzayBJRAogIGludCB0YXNrX2lkOwogIE1QSV9Db21tX3JhbmsoTVBJX0NPTU1fV09STEQsICZ0YXNrX2lkKTsKCiAgLy8gU2V0IHVwIHRoZSBzdHJpbmcgYW5kIHByaW50CiAgc3RkOjpzdHJpbmdzdHJlYW0gc3M7CiAgc3MgPDwgIlByaW50aW5nIGZyb20gdGFzayAiIDw8IHRhc2tfaWQgPDwgJy8nIDw8IG51bV90YXNrcyA8PCAnXG4nOwogIHN0ZDo6Y291dCA8PCBzcy5zdHIoKTsKCiAgLy8gRmluaXNoIG91ciBNUEkgd29yawogIE1QSV9GaW5hbGl6ZSgpOwogIHJldHVybiAwOwp9Cg==