Actual source code: ex1.c
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: {
13: PetscMPIInt rank,size;
15: /*
16: Every PETSc program should begin with the PetscInitialize() routine.
17: argc, argv - These command line arguments are taken to extract the options
18: supplied to PETSc and options supplied to MPI.
19: help - When PETSc executable is invoked with the option -help,
20: it prints the various options that can be applied at
21: runtime. The user can use the "help" variable to place
22: additional help messages in this printout.
23: */
24: PetscInitialize(&argc,&argv,(char*)0,help);
26: /*
27: The following MPI calls return the number of processes
28: being used and the rank of this process in the group.
29: */
30: MPI_Comm_size(PETSC_COMM_WORLD,&size);
31: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
33: /*
34: Here we would like to print only one message that represents
35: all the processes in the group. We use PetscPrintf() with the
36: communicator PETSC_COMM_WORLD. Thus, only one message is
37: printed representng PETSC_COMM_WORLD, i.e., all the processors.
38: */
39: PetscPrintf(PETSC_COMM_WORLD,"Number of processors = %d, rank = %d\n",size,rank);
41: /*
42: Here a barrier is used to separate the two program states.
43: */
44: MPI_Barrier(PETSC_COMM_WORLD);
46: /*
47: Here we simply use PetscPrintf() with the communicator PETSC_COMM_SELF,
48: where each process is considered separately and prints independently
49: to the screen. Thus, the output from different processes does not
50: appear in any particular order.
51: */
53: PetscPrintf(PETSC_COMM_SELF,"[%d] Jumbled Hello World\n",rank);
55: /*
56: Always call PetscFinalize() before exiting a program. This routine
57: - finalizes the PETSc libraries as well as MPI
58: - provides summary and diagnostic information if certain runtime
59: options are chosen (e.g., -log_view). See PetscFinalize()
60: manpage for more information.
61: */
62: PetscFinalize();
63: return 0;
64: }
66: /*TEST
68: test:
70: TEST*/