Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <mpi.h>
- #include <iostream>
- #include <sstream>
- using namespace std;
- void myFunc(long long int *inp, long long int *inout, int *n, MPI_Datatype *type) {
- for (int i=0; i<*n; i++) {
- long long int mod = 10;
- while (mod <= inout[i]) mod*=10;
- inout[i] += inp[i]*mod;
- stringstream buf;
- buf << inout[i] << endl;
- cout << buf.str();
- }
- }
- int main(int argc, char *argv[])
- {
- int myrank, tag = 0;
- MPI_Status status;
- MPI_Init(&argc, &argv);
- MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
- long long int myData[] = {myrank+1};
- long long int result[1] = {-1};
- MPI_Op myOp;
- MPI_Op_create((MPI_User_function*)myFunc, true, &myOp);
- MPI_Reduce(myData, result, 1, MPI_LONG, myOp, 0, MPI_COMM_WORLD);
- if (myrank == 0) cout << result[0] << endl;
- MPI_Op_free(&myOp);
- MPI_Finalize();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment