Epetra Package Browser (Single Doxygen Collection) Development
example/ImportExport_LL/cxx_main.cpp
Go to the documentation of this file.
00001 //@HEADER
00002 // ************************************************************************
00003 // 
00004 //               Epetra: Linear Algebra Services Package 
00005 //                 Copyright 2011 Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00038 // 
00039 // ************************************************************************
00040 //@HEADER
00041 
00042 #include <stdio.h>
00043 #include <stdlib.h>
00044 #include <ctype.h>
00045 #include <assert.h>
00046 #include <string.h>
00047 #include <math.h>
00048 #include <iostream>
00049 #include "mpi.h"
00050 #include "Epetra_MpiComm.h"
00051 #include "Epetra_Map.h"
00052 #include "Epetra_LocalMap.h"
00053 #include "Epetra_Vector.h" 
00054 #include "Epetra_Import.h"
00055 #include "Epetra_Export.h"
00056 int main(int argc, char *argv[])
00057 {
00058   using namespace std;
00059   MPI_Init(&argc,&argv);
00060   Epetra_MpiComm Comm( MPI_COMM_WORLD );
00061 
00062   cout << Comm <<endl;
00063 
00064   if (Comm.NumProc()!=3) cout << "Must be run on 3 MPI processes." << endl;
00065 
00066   char tmp;
00067   if (Comm.MyPID()==0) cout << "Press any key to continue..."<< endl;
00068   if (Comm.MyPID()==0) cin >> tmp;
00069   Comm.Barrier();
00070   int NumMyElements = 2;
00071   Epetra_Map SourceMap((long long) -1, NumMyElements, 0, Comm);
00072   long long NumGlobalElements = SourceMap.NumGlobalElements64();
00073   
00074   Epetra_Vector SourceX(SourceMap);
00075 
00076   // Define SourceX = [0, 1, 2, 3, 4, 5]' with 2 elements per process
00077 
00078   SourceX[0] = (double) SourceMap.GID64(0);
00079   SourceX[1] = (double) SourceMap.GID64(1);
00080 
00081   cout << SourceX; // Print it to stdout
00082 
00083   // Construct first target map: PE0 gets all elements of SourceX
00084 
00085   long long TargetOneNumMyElements;
00086   if (Comm.MyPID()==0) TargetOneNumMyElements = NumGlobalElements;
00087   else TargetOneNumMyElements = 0;
00088 
00089   Epetra_Map TargetOneMap((long long) -1, TargetOneNumMyElements, 0, Comm);
00090 
00091   Epetra_Import ImporterOne(TargetOneMap, SourceMap);
00092 
00093   Epetra_Vector TargetOneX(TargetOneMap);
00094 
00095   TargetOneX.Import(SourceX, ImporterOne, Insert);
00096 
00097   cout << TargetOneX << endl;
00098 
00099   long long * GlobalElementList = new long long[2];
00100   GlobalElementList[0] = 5 - SourceMap.GID64(0);
00101   GlobalElementList[1] = 5 - SourceMap.GID64(1);
00102   
00103   Epetra_Map TargetTwoMap((long long) -1, 2, GlobalElementList, 0, Comm);
00104 
00105   Epetra_Import ImporterTwo(TargetTwoMap, TargetOneMap);
00106 
00107   Epetra_Vector TargetTwoX(TargetTwoMap);
00108 
00109   TargetTwoX.Import(TargetOneX, ImporterTwo, Insert);
00110 
00111   cout << TargetTwoX << endl;
00112   
00113   Epetra_LocalMap TargetThreeMap((long long) 6, 0, Comm);
00114 
00115   Epetra_Import ImporterThree(TargetThreeMap, TargetOneMap);
00116 
00117   Epetra_Vector TargetThreeX(TargetThreeMap);
00118 
00119   TargetThreeX.Import(TargetOneX, ImporterThree, Insert);
00120 
00121   cout << TargetThreeX << endl;
00122   
00123   Epetra_Export ExporterOne(TargetThreeMap, SourceMap);
00124 
00125   Epetra_Vector TargetFourX(SourceMap);
00126 
00127   TargetFourX.Import(TargetThreeX, ExporterOne, Add);
00128 
00129   cout << TargetFourX << endl;
00130   
00131 
00132 
00133   MPI_Finalize();
00134   return 0;
00135 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines