Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Code Below: // #include #include #include using std::cout; using std::ios; using std::cerr; #include using std::ifstream; #define MAXSIZE 1000 // using namespace std; // int main(int
Code Below:
// #include#include #include using std::cout; using std::ios; using std::cerr; #include using std::ifstream; #define MAXSIZE 1000 // using namespace std; // int main(int argc, char **argv) { int myid, numprocs, greatest, data[MAXSIZE], i, x, low, high, result, packet[2]; // [0] = local sum, [1] = local max // // ofstream DebugFile; // Debug file. // // MPI initialization routines. // MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD,&numprocs); MPI_Comm_rank(MPI_COMM_WORLD,&myid); // // Activity for root process, 0. // if (myid == 0) { // // Read file containing MAXSIZE numbers. // std::ifstream infile("rand_data.txt", ios::in); // //DebugFile.open ("rand_dataV1.txt"); //DebugFile << "Writing this to a file. "; // if( !infile ) { // checks for file access cerr << "File could not be opened "; return( 1 ); } //if( numprocs != 10 ) // // Check that the number of subdivisions of the file is a multiple of // the number of processes. // if( MAXSIZE%numprocs != 0 ) { cerr << " !!! WARNING - This program requires MAXSIZE%numprocs == 0 processes "; return( 2 ); } for(i = 0; i < MAXSIZE; i++) // load data from file into an array { infile >> data[i]; // // DebugFile< packet[1] ) packet[1] = data[i]; packet[0] += data[i]; // // Error check output. // // DebugFile< Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started