NERSC logo National Energy Research Scientific Computing Center
  A DOE Office of Science User Facility
  at Lawrence Berkeley National Laboratory
 

C++/MPI "hello" example

/scratchdir => cat mpi-hello.C
 
#include <mpi.h>
#include <iostream>
using namespace std;
 
int main(int argc, char* argv[])
{
 int myid, numprocs;
 
 MPI_Init(&argc,&argv);
 MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
 MPI_Comm_rank(MPI_COMM_WORLD,&myid); 
 
 cout << "Hello from proc " << myid << " of " << numprocs << endl;
 
 MPI_Finalize();
}


/scratchdir => cat runhelloC
#PBS -N helloCjob
#PBS -q debug
#PBS -l mppwidth=2
#PBS -l walltime=00:01:00
#PBS -e helloCjob.out
#PBS -j eo
 
cd $PBS_O_WORKDIR
 
CC -fast -o mpi-helloC mpi-hello.C   #compiler runs on login node
aprun -n 2 ./mpi-helloC              #launch parallel job on compute nodes


/scratchdir => qsub runhelloC
876.xxx0000n

/scratchdir => cat helloCjob.out
Warning: no access to tty (Bad file descriptor).
Thus no job control in this shell.
/opt/xt-pe/2.0.10/bin/snos64/CC: INFO: linux target is being used
mpi-hello.C:
Hello from proc 0 of 2
Hello from proc 1 of 2
Application 62060 resources: utime 0, stime 0


LBNL Home
Page last modified: Tue, 30 Oct 2007 20:43:54 GMT
Page URL: http://www.nersc.gov/nusers/systems/franklin/programming/ex2.php
Web contact: webmaster@nersc.gov
Computing questions: consult@nersc.gov

Privacy and Security Notice
DOE Office of Science