Changes between Initial Version and Version 1 of cypress/Programming/CppExamples/MpiCpp


Ignore:
Timestamp:
May 15, 2015 9:53:33 AM (4 years ago)
Author:
cmaggio
Comment:

migrated content from ccs wiki

Legend:

Unmodified
Added
Removed
Modified
  • cypress/Programming/CppExamples/MpiCpp

    v1 v1  
     1= MPI C++ =
     2== Hello World ==
     3{{{#!cpp
     4//
     5//  hello_mpi.cpp: display a message on the screen
     6//
     7#include <iostream>
     8#include <mpi.h>
     9 
     10int main (int argc, char *argv[]) {
     11  // Initialize
     12  MPI::Init(argc, argv);
     13 
     14  // get myid and # of processors
     15  int numproc = MPI::COMM_WORLD.Get_size();
     16  int myid = MPI::COMM_WORLD.Get_rank();
     17 
     18  std::cout << "hello from " << myid << std::endl;
     19 
     20  // wait until all processors come here
     21  MPI::COMM_WORLD.Barrier();
     22 
     23  if ( myid == 0 ) {
     24    // only myid = 0 do this
     25    std::cout << numproc << " processors said hello!" << std::endl;
     26  }
     27 
     28  MPI::Finalize();
     29}
     30}}}
     31== Compile ==
     32{{{mpiCC hello_mpi.cpp}}}
     33== Example of Jobscript ==
     34[[https://wiki.hpc.tulane.edu/trac/wiki/cypress/Programming/Cexamples#ExamplesofJobscript|See Example]]