CppNoddy  0.92
Loading...
Searching...
No Matches
DistributedVector_petscd.cpp
Go to the documentation of this file.
1/// \file DistributedVector_petscd.cpp
2/// \ingroup Tests
3/// \ingroup Vector
4/// A superficial sanity check of copy and two_norm
5
6#include <DistributedVector.h>
7#include <Types.h>
8#include "../Utils_Fill.h"
9#include <mpi.h>
10
11using namespace std;
12using namespace CppNoddy;
13
14
15int main(int argc, char *argv[])
16{
17 PetscSession::getInstance(argc,argv);
18
19 PetscPrintf(PETSC_COMM_WORLD, "\n=== Vector: A distributed (double) example ==========\n\n");
20
21 DistributedVector<double> vecA( 10 );
22
23 DenseVector<int> indices( 5, 0 );
24 DenseVector<double> values( 5, 1.0);
25 for ( auto i = 0; i < 5; i++ ) {
26 indices[i] = 2*i;
27 values[i] = 2*i;
28 }
29 vecA.set( indices, values );
30 vecA.final_assembly();
31
32 auto vecB = vecA;
33
34 vecA.view();
35 //vecB.view();
36 PetscPrintf(PETSC_COMM_WORLD, "%f", vecA.two_norm() - vecB.two_norm() );
37
38 if ( vecA.two_norm() - vecB.two_norm() > 1.e-12 )
39 {
40 PetscPrintf(PETSC_COMM_WORLD, "\033[1;31;48m * FAILED \033[0m\n");
41 return 1;
42 }
43 PetscPrintf(PETSC_COMM_WORLD, "\033[1;32;48m * PASSED \033[0m\n");
44 return 0;
45
46}
47
48
49
int main()
Definition: ArcCircle.cpp:39
A class that constructs a SPARSE/DISTRIBUTED vector using PETSc.
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...

© 2012

R.E. Hewitt