example/ImportExport/cxx_main.cpp

Go to the documentation of this file.
00001 //@HEADER
00002 // ************************************************************************
00003 // 
00004 //               Epetra: Linear Algebra Services Package 
00005 //                 Copyright (2001) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ************************************************************************
00027 //@HEADER
00028 
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <ctype.h>
00032 #include <assert.h>
00033 #include <string.h>
00034 #include <math.h>
00035 #include "mpi.h"
00036 #include "Epetra_MpiComm.h"
00037 #include "Epetra_Map.h"
00038 #include "Epetra_LocalMap.h"
00039 #include "Epetra_Vector.h" 
00040 #include "Epetra_Import.h"
00041 #include "Epetra_Export.h"
00042 int main(int argc, char *argv[])
00043 {
00044   MPI_Init(&argc,&argv);
00045   Epetra_MpiComm Comm( MPI_COMM_WORLD );
00046 
00047   cout << Comm <<endl;
00048 
00049   if (Comm.NumProc()!=3) cout << "Must be run on 3 MPI processes." << endl;
00050 
00051   char tmp;
00052   if (Comm.MyPID()==0) cout << "Press any key to continue..."<< endl;
00053   if (Comm.MyPID()==0) cin >> tmp;
00054   Comm.Barrier();
00055   int NumMyElements = 2;
00056   Epetra_Map SourceMap(-1, NumMyElements, 0, Comm);
00057   int NumGlobalElements = SourceMap.NumGlobalElements();
00058   
00059   Epetra_Vector SourceX(SourceMap);
00060 
00061   // Define SourceX = [0, 1, 2, 3, 4, 5]' with 2 elements per process
00062 
00063   SourceX[0] = (double) SourceMap.GID(0);
00064   SourceX[1] = (double) SourceMap.GID(1);
00065 
00066   cout << SourceX; // Print it to stdout
00067 
00068   // Construct first target map: PE0 gets all elements of SourceX
00069 
00070   int TargetOneNumMyElements;
00071   if (Comm.MyPID()==0) TargetOneNumMyElements = NumGlobalElements;
00072   else TargetOneNumMyElements = 0;
00073 
00074   Epetra_Map TargetOneMap(-1, TargetOneNumMyElements, 0, Comm);
00075 
00076   Epetra_Import ImporterOne(TargetOneMap, SourceMap);
00077 
00078   Epetra_Vector TargetOneX(TargetOneMap);
00079 
00080   TargetOneX.Import(SourceX, ImporterOne, Insert);
00081 
00082   cout << TargetOneX << endl;
00083 
00084   int * GlobalElementList = new int[2];
00085   GlobalElementList[0] = 5 - SourceMap.GID(0);
00086   GlobalElementList[1] = 5 - SourceMap.GID(1);
00087   
00088   Epetra_Map TargetTwoMap(-1, 2, GlobalElementList, 0, Comm);
00089 
00090   Epetra_Import ImporterTwo(TargetTwoMap, TargetOneMap);
00091 
00092   Epetra_Vector TargetTwoX(TargetTwoMap);
00093 
00094   TargetTwoX.Import(TargetOneX, ImporterTwo, Insert);
00095 
00096   cout << TargetTwoX << endl;
00097   
00098   Epetra_LocalMap TargetThreeMap(6, 0, Comm);
00099 
00100   Epetra_Import ImporterThree(TargetThreeMap, TargetOneMap);
00101 
00102   Epetra_Vector TargetThreeX(TargetThreeMap);
00103 
00104   TargetThreeX.Import(TargetOneX, ImporterThree, Insert);
00105 
00106   cout << TargetThreeX << endl;
00107   
00108   Epetra_Export ExporterOne(TargetThreeMap, SourceMap);
00109 
00110   Epetra_Vector TargetFourX(SourceMap);
00111 
00112   TargetFourX.Import(TargetThreeX, ExporterOne, Add);
00113 
00114   cout << TargetFourX << endl;
00115   
00116 
00117 
00118   MPI_Finalize();
00119   return 0;
00120 }

Generated on Wed May 12 21:41:04 2010 for Epetra Package Browser (Single Doxygen Collection) by  doxygen 1.4.7