MPI: Difference between revisions

Jump to navigation Jump to search
786 bytes added ,  7 years ago
Line 424: Line 424:
     MPI_Finalize();
     MPI_Finalize();
     return(0);
     return(0);
}
}}
</tab>
<tab name="Boost (C++)">
{{File
  |name=phello.cpp
  |lang="cpp"
  |contents=
#include <iostream>
#include <string>
#include <boost/mpi.hpp>
using namespace std;
using namespace boost;
int main(int argc, char *argv[])
{
    mpi::environment env(argc, argv);
    mpi::communicator world;
    int rank = world.rank();
    int size = world.size();
    string outmessage = "Hello, world! from process " + to_string(rank) + " of " + to_string(size);
    string inmessage;
    int sendto = (rank + 1) % size;
    int recvfrom = (rank + size - 1) % size;
    cout << outmessage << endl;
    world.send(sendto,0,outmessage);
    world.recv(recvfrom,0,inmessage);
    cout << "[P_" << rank << "] process " << recvfrom << " said: \"" << inmessage << "\"" << endl;
    return 0;
}
}
}}
}}
Bureaucrats, cc_docs_admin, cc_staff, rsnt_translations
2,837

edits

Navigation menu