tminres
TrilinosExample/testEpetraVectorAdapter.cpp
Go to the documentation of this file.
00001 // tminres is free software; you can redistribute it and/or modify it under the
00002 // terms of the GNU Lesser General Public License (as published by the Free
00003 // Software Foundation) version 2.1 dated February 1999.
00004 //
00005 // Authors:
00006 // - Umberto Villa, Emory University - uvilla@emory.edu
00007 // - Michael Saunders, Stanford University
00008 // - Santiago Akle, Stanford University
00009 
00016 /*
00017  * This code checks the implementation of the methods in EpetraVectorAdapter.
00018  *
00019  * mpirun -n 2 xterm -e " ./testEpetraVectorAdapter.exe; read -p 'Press enter to close window' "
00020  */
00021 
00022 
00023 #include "EpetraVectorAdapter.hpp"
00024 
00025 #include <Epetra_ConfigDefs.h>
00026 #include <Epetra_MpiComm.h>
00027 #include <mpi.h>
00028 #include <Epetra_Map.h>
00029 #include <Epetra_Vector.h>
00030 
00031 int main(int argc,char * argv[])
00032 {
00033 
00034         MPI_Init(&argc, &argv);
00035         std::cout<< "MPI Initialization\n";
00036 
00037         Epetra_MpiComm * comm(new Epetra_MpiComm(MPI_COMM_WORLD));
00038         {
00039         int myPid(comm->MyPID());
00040         int nProc(comm->NumProc());
00041 
00042         int nEl(5*nProc);
00043         Epetra_Map map(nEl, 0, *comm);
00044 
00045         Epetra_Vector aev(map), bev(map), cev(map), dev(map);
00046 
00047         EpetraVectorAdapter a(aev), b(bev), c(cev), d(dev);
00048         a = 1.0;
00049         std::cout<< "a = ";
00050         a.Print(std::cout);
00051 
00052         b.Randomize(1);
00053         std::cout<< "b = ";
00054         b.Print(std::cout);
00055 
00056         c = b;
00057         std::cout<< "c = b =";
00058         c.Print(std::cout);
00059 
00060         c.Scale(-1.);
00061         std::cout << "c * (-1.) = ";
00062         c.Print(std::cout);
00063 
00064         d.Randomize(2);
00065         std::cout<<"d = ";
00066         d.Print(std::cout);
00067 
00068         subtract(d,b, a);
00069         std::cout << "a = d - b = ";
00070         a.Print(std::cout);
00071 
00072         add(d, 5., b, a);
00073         std::cout<< " a = d + 5.*b = ";
00074         a.Print(std::cout);
00075 
00076         add(0.5, d, 2.5, b, a);
00077         std::cout<< "a = 0.5 * d + 2.5*b = ";
00078         a.Print(std::cout);
00079 
00080         add(2., d, b, a);
00081         std::cout<< "a = 2* (d + b) = ";
00082         a.Print(std::cout);
00083 
00084         add(b,d,c, a);
00085         std::cout << "a = b + c + d = ";
00086         a.Print(std::cout);
00087 
00088         std::cout << "InnerProduct(b,d) = " << InnerProduct(b,d) << "\n";
00089 
00090         }
00091         delete comm;
00092         MPI_Finalize();
00093 
00094         return 0;
00095 }
 All Classes Files Functions Friends