Actual source code: ex1.c

petsc-dev 2014-07-21
Report Typos and Errors
  2: static char help[] = "Introductory example that illustrates printing.\n\n";

  4: /*T
  5:    Concepts: introduction to PETSc;
  6:    Concepts: printing^in parallel
  7:    Processors: n
  8: T*/

 10: #include <petscsys.h>
 11: int main(int argc,char **argv)
 12: {
 14:   PetscMPIInt    rank,size;

 16:   /*
 17:     Every PETSc routine should begin with the PetscInitialize() routine.
 18:     argc, argv - These command line arguments are taken to extract the options
 19:                  supplied to PETSc and options supplied to MPI.
 20:     help       - When PETSc executable is invoked with the option -help,
 21:                  it prints the various options that can be applied at
 22:                  runtime.  The user can use the "help" variable place
 23:                  additional help messages in this printout.
 24:   */
 25:   PetscInitialize(&argc,&argv,(char*)0,help);

 27:   /*
 28:      The following MPI calls return the number of processes
 29:      being used and the rank of this process in the group.
 30:    */
 31:   MPI_Comm_size(PETSC_COMM_WORLD,&size);
 32:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);

 34:   /*
 35:      Here we would like to print only one message that represents
 36:      all the processes in the group.  We use PetscPrintf() with the
 37:      communicator PETSC_COMM_WORLD.  Thus, only one message is
 38:      printed representng PETSC_COMM_WORLD, i.e., all the processors.
 39:   */
 40:   PetscPrintf(PETSC_COMM_WORLD,"Number of processors = %d, rank = %d\n",size,rank);

 42:   /*
 43:     Here a barrier is used to separate the two program states.
 44:   */
 45:   MPI_Barrier(PETSC_COMM_WORLD);

 47:   /*
 48:     Here we simply use PetscPrintf() with the communicator PETSC_COMM_SELF,
 49:     where each process is considered separately and prints independently
 50:     to the screen.  Thus, the output from different processes does not
 51:     appear in any particular order.
 52:   */

 54:   PetscPrintf(PETSC_COMM_SELF,"[%d] Jumbled Hello World\n",rank);

 56:   /*
 57:      Always call PetscFinalize() before exiting a program.  This routine
 58:        - finalizes the PETSc libraries as well as MPI
 59:        - provides summary and diagnostic information if certain runtime
 60:          options are chosen (e.g., -log_summary).  See PetscFinalize()
 61:      manpage for more information.
 62:   */
 63:   PetscFinalize();
 64:   return 0;
 65: }