example/C_wrappers/c_main.c

Go to the documentation of this file.
00001 #ifdef EPETRA_MPI
00002 #include <mpi.h>
00003 #endif
00004 #include "Epetra_C_wrappers.h"
00005 
00006 int main(int argc, char *argv[]) {
00007   int i;
00008   EPETRA_OBJECT_PTR Comm, Map, X, Y;
00009   int MyPID, NumProc;
00010   int NumGlobalElements;
00011   int NumMyElements;
00012 
00013 #ifdef EPETRA_MPI
00014   /* Initialize MPI */
00015   MPI_Init(&argc,&argv);
00016   Comm = epetra_mpicomm_create2( MPI_COMM_WORLD );
00017 #else
00018   Comm = epetra_serialcomm_create();
00019 #endif
00020 
00021    MyPID = epetra_comm_mypid(Comm);
00022    NumProc = epetra_comm_numproc(Comm);
00023 
00024 
00025    /* Construct a Map that puts 2 elements on each PE */
00026 
00027    NumGlobalElements = 2*NumProc;
00028    Map = epetra_map_create1(NumGlobalElements, 0, Comm);
00029   
00030  
00031   X = epetra_vector_create1(Map);
00032   Y = epetra_vector_create1(Map);
00033 
00034   epetra_vector_random(X);
00035   epetra_vector_random(Y);
00036   printf("Contents of X vector\n");
00037   epetra_vector_print(X);
00038 
00039 
00040   printf("Contents of Y vector\n");
00041   epetra_vector_print(Y);
00042 
00043   /* Add X and Y (need to pass Y twice for now, since this is the only update 
00044      interface wrapped by C at this time) */
00045   epetra_vector_update(X, 1.0, Y, 0.0, Y, 1.0);
00046 
00047   printf("Sum of X and Y vectors\n");
00048   epetra_vector_print(X);
00049 
00050   epetra_vector_destroy(X);
00051   epetra_vector_destroy(Y);
00052   epetra_map_destroy(Map);
00053   epetra_comm_destroy(Comm);
00054   
00055 #ifdef EPETRA_MPI
00056   MPI_Finalize() ;
00057 #endif
00058 
00059 /* end main
00060 */
00061 return 0 ;
00062 }

Generated on Thu Sep 18 12:37:56 2008 for Epetra Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1