~chaffra/+junk/trilinos

« back to all changes in this revision

Viewing changes to packages/belos/tpetra/test/MVOPTester/cxx_main_complex.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme, Christophe Prud'homme, Johannes Ring
  • Date: 2009-12-13 12:53:22 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20091213125322-in0nrdjc55deqsw9
Tags: 10.0.3.dfsg-1
[Christophe Prud'homme]
* New upstream release

[Johannes Ring]
* debian/patches/libname.patch: Add prefix 'libtrilinos_' to all
  libraries. 
* debian/patches/soname.patch: Add soversion to libraries.
* debian/watch: Update download URL.
* debian/control:
  - Remove python-numeric from Build-Depends (virtual package).
  - Remove automake and autotools from Build-Depends and add cmake to
    reflect switch to CMake.
  - Add python-support to Build-Depends.
* debian/rules: 
  - Cleanup and updates for switch to CMake.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//@HEADER
2
 
// ************************************************************************
3
 
// 
4
 
//
5
 
//                 Belos: Block Linear Solvers Package
6
 
//                 Copyright (2004) Sandia Corporation
7
 
// 
8
 
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9
 
// license for use of this work by or on behalf of the U.S. Government.
10
 
// 
11
 
// This library is free software; you can redistribute it and/or modify
12
 
// it under the terms of the GNU Lesser General Public License as
13
 
// published by the Free Software Foundation; either version 2.1 of the
14
 
// License, or (at your option) any later version.
15
 
//  
16
 
// This library is distributed in the hope that it will be useful, but
17
 
// WITHOUT ANY WARRANTY; without even the implied warranty of
18
 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19
 
// Lesser General Public License for more details.
20
 
//  
21
 
// You should have received a copy of the GNU Lesser General Public
22
 
// License along with this library; if not, write to the Free Software
23
 
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24
 
// USA
25
 
// Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
26
 
// 
27
 
// ************************************************************************
28
 
//@HEADER
29
 
//
30
 
//  This test instantiates the Belos classes using a std::complex scalar type
31
 
//  and checks functionality.
32
 
//
33
 
 
34
1
#include <Teuchos_UnitTestHarness.hpp>
35
2
#include <Tpetra_DefaultPlatform.hpp>
36
3
#include <Tpetra_CrsMatrix.hpp>
40
7
#include "BelosTpetraAdapter.hpp"
41
8
#include "BelosOutputManager.hpp"
42
9
 
43
 
// I/O for Harwell-Boeing files
44
 
#ifdef HAVE_BELOS_TRIUTILS
45
 
#include "iohb.h"
46
 
#endif
47
 
 
48
10
namespace {
49
11
 
50
 
  using Teuchos::as;
 
12
  using Teuchos::tuple;
51
13
  using Teuchos::RCP;
52
 
  using Teuchos::ArrayRCP;
53
14
  using Teuchos::rcp;
 
15
  using Teuchos::rcpFromRef;
 
16
  using Tpetra::LocallyReplicated;
54
17
  using Tpetra::Map;
55
18
  using Tpetra::DefaultPlatform;
56
 
  using Tpetra::Platform;
57
 
  using std::vector;
58
 
  using std::sort;
59
 
  using Teuchos::arrayViewFromVector;
60
 
  using Teuchos::broadcast;
 
19
  using Tpetra::MultiVector;
 
20
  using Tpetra::CrsMatrix;
 
21
  using Tpetra::Operator;
 
22
  using Tpetra::global_size_t;
61
23
  using Teuchos::OrdinalTraits;
62
24
  using Teuchos::ScalarTraits;
63
25
  using Teuchos::Comm;
64
 
  using Tpetra::MultiVector;
65
 
  using Tpetra::CrsMatrix;
66
26
  using std::endl;
67
 
  using Teuchos::Array;
68
 
  using Teuchos::ArrayView;
69
 
  using Teuchos::NO_TRANS;
70
 
  using Teuchos::TRANS;
71
 
  using Teuchos::CONJ_TRANS;
72
27
  using Belos::OutputManager;
73
28
  using Belos::Warnings;
74
29
 
75
30
  bool testMpi = true;
76
31
  double errorTolSlack = 1e+1;
77
32
 
78
 
#define PRINT_VECTOR(v) \
79
 
   { \
80
 
     out << #v << ": "; \
81
 
     copy(v.begin(), v.end(), ostream_iterator<Ordinal>(out," ")); \
82
 
     out << endl; \
83
 
   }
84
 
 
85
33
  TEUCHOS_STATIC_SETUP()
86
34
  {
87
35
    Teuchos::CommandLineProcessor &clp = Teuchos::UnitTestRepository::getCLP();
95
43
        "Slack off of machine epsilon used to check test results" );
96
44
  }
97
45
 
98
 
  template<class Ordinal>
99
 
  RCP<const Platform<Ordinal> > getDefaultPlatform()
 
46
  RCP<const Comm<int> > getDefaultComm()
100
47
  {
 
48
    RCP<const Comm<int> > ret;
101
49
    if (testMpi) {
102
 
      return DefaultPlatform<Ordinal>::getPlatform();
103
 
    }
104
 
    return rcp(new Tpetra::SerialPlatform<Ordinal>());
 
50
      ret = DefaultPlatform::getDefaultPlatform().getComm();
 
51
    }
 
52
    else {
 
53
     ret = rcp(new Teuchos::SerialComm<int>());
 
54
    }
 
55
    return ret;
105
56
  }
106
57
 
107
 
  template<class Ordinal, class Scalar> 
108
 
  RCP<CrsMatrix<Ordinal,Scalar> > constructTriDiagMatrix(const Map<Ordinal> &map) 
 
58
  template<class Scalar, class LO, class GO>
 
59
  RCP<CrsMatrix<Scalar,LO,GO> > constructDiagMatrix(const RCP<const Map<LO,GO> > &map) 
109
60
  {
110
 
    RCP<CrsMatrix<Ordinal,Scalar> > op = rcp( new CrsMatrix<Ordinal,Scalar>(map) );
 
61
    // create identity matrix
 
62
    RCP<CrsMatrix<Scalar,LO,GO> > op = rcp( new CrsMatrix<Scalar,LO,GO>(map,1) );
 
63
    for (size_t lid=0; lid < map->getNodeNumElements(); ++lid) {
 
64
      op->insertGlobalValues(map->getGlobalElement(lid),tuple(map->getGlobalElement(lid)), tuple(ScalarTraits<Scalar>::one()));
 
65
    }
111
66
    op->fillComplete();
112
67
    return op;
113
68
  }
117
72
  // 
118
73
 
119
74
  ////
120
 
  TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( MultiVector, MVTestDist, Ordinal, Scalar )
121
 
  {
122
 
    typedef Tpetra::MultiVector<Ordinal,Scalar> MV;
123
 
    const Ordinal dim = 500;
124
 
    const Ordinal numVecs = 5;
125
 
    const Ordinal ZERO = OrdinalTraits<Ordinal>::zero();
126
 
    // Create an output manager to handle the I/O from the solver
127
 
    RCP<OutputManager<Scalar> > MyOM = rcp( new OutputManager<Scalar>(Warnings,rcp(&out,false)) );
128
 
    // create a platform  
129
 
    const Platform<Ordinal> & platform = *(getDefaultPlatform<Ordinal>());
130
 
    // create a comm  
131
 
    RCP<Comm<Ordinal> > comm = platform.createComm();
132
 
    // create a uniform contiguous map
133
 
    Map<Ordinal> map(dim,ZERO,platform);
134
 
    RCP<MV> mvec = rcp( new MV(map,numVecs,true) );
135
 
    bool res = Belos::TestMultiVecTraits<Scalar,MV>(MyOM,mvec);
136
 
    TEST_EQUALITY_CONST(res,true);
137
 
    // All procs fail if any proc fails
138
 
    int globalSuccess_int = -1;
139
 
    reduceAll( *comm, Teuchos::REDUCE_SUM, success ? 0 : 1, &globalSuccess_int );
140
 
    TEST_EQUALITY_CONST( globalSuccess_int, 0 );
141
 
  }
142
 
 
143
 
  ////
144
 
  TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( MultiVector, MVTestLocal, Ordinal, Scalar )
145
 
  {
146
 
    typedef Tpetra::MultiVector<Ordinal,Scalar> MV;
147
 
    const Ordinal dim = 500;
148
 
    const Ordinal numVecs = 5;
149
 
    const Ordinal ZERO = OrdinalTraits<Ordinal>::zero();
150
 
    // Create an output manager to handle the I/O from the solver
151
 
    RCP<OutputManager<Scalar> > MyOM = rcp( new OutputManager<Scalar>(Warnings,rcp(&out,false)) );
152
 
    // create a platform  
153
 
    const Platform<Ordinal> & platform = *(getDefaultPlatform<Ordinal>());
154
 
    // create a comm  
155
 
    RCP<Comm<Ordinal> > comm = platform.createComm();
156
 
    // create a uniform contiguous map
157
 
    Map<Ordinal> map(dim,ZERO,platform,true);
158
 
    RCP<MV> mvec = rcp( new MV(map,numVecs,true) );
159
 
    bool res = Belos::TestMultiVecTraits<Scalar,MV>(MyOM,mvec);
160
 
    TEST_EQUALITY_CONST(res,true);
161
 
    // All procs fail if any proc fails
162
 
    int globalSuccess_int = -1;
163
 
    reduceAll( *comm, Teuchos::REDUCE_SUM, success ? 0 : 1, &globalSuccess_int );
164
 
    TEST_EQUALITY_CONST( globalSuccess_int, 0 );
165
 
  }
166
 
 
167
 
  ////
168
 
  TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( MultiVector, OPTestLocal, Ordinal, Scalar )
169
 
  {
170
 
    typedef Tpetra::MultiVector<Ordinal,Scalar> MV;
171
 
    typedef Tpetra::Operator<Ordinal,Scalar>    OP;
172
 
    // const Ordinal dim = 500;
173
 
    const Ordinal dim = 10;
174
 
    const Ordinal numVecs = 5;
175
 
    const Ordinal ZERO = OrdinalTraits<Ordinal>::zero();
176
 
    // Create an output manager to handle the I/O from the solver
177
 
    RCP<OutputManager<Scalar> > MyOM = rcp( new OutputManager<Scalar>(Warnings,rcp(&out,false)) );
178
 
    // create a platform  
179
 
    const Platform<Ordinal> & platform = *(getDefaultPlatform<Ordinal>());
180
 
    // create a comm  
181
 
    RCP<Comm<Ordinal> > comm = platform.createComm();
 
75
  TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( MultiVector, MVTestDist, LO, GO, Scalar )
 
76
  {
 
77
    typedef MultiVector<Scalar,LO,GO> MV;
 
78
    const global_size_t dim = 500;
 
79
    const size_t numVecs = 5;
 
80
    // Create an output manager to handle the I/O from the solver
 
81
    RCP<OutputManager<Scalar> > MyOM = rcp( new OutputManager<Scalar>(Warnings,rcpFromRef(out)) );
 
82
    // get a comm
 
83
    RCP<const Comm<int> > comm = getDefaultComm();
 
84
    // create a uniform contiguous map
 
85
    RCP<const Map<LO,GO> > map = rcp( new Map<LO,GO>(dim,static_cast<GO>(0),comm) );
 
86
    RCP<MV> mvec = rcp( new MV(map,numVecs,true) );
 
87
    bool res = Belos::TestMultiVecTraits<Scalar,MV>(MyOM,mvec);
 
88
    TEST_EQUALITY_CONST(res,true);
 
89
    // All procs fail if any proc fails
 
90
    int globalSuccess_int = -1;
 
91
    reduceAll( *comm, Teuchos::REDUCE_SUM, success ? 0 : 1, &globalSuccess_int );
 
92
    TEST_EQUALITY_CONST( globalSuccess_int, 0 );
 
93
  }
 
94
 
 
95
  ////
 
96
  TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( MultiVector, MVTestLocal, LO, GO, Scalar )
 
97
  {
 
98
    typedef MultiVector<Scalar,LO,GO> MV;
 
99
    const global_size_t dim = 500;
 
100
    const size_t numVecs = 5;
 
101
    // Create an output manager to handle the I/O from the solver
 
102
    RCP<OutputManager<Scalar> > MyOM = rcp( new OutputManager<Scalar>(Warnings,rcpFromRef(out)) );
 
103
    // get a comm
 
104
    RCP<const Comm<int> > comm = getDefaultComm();
 
105
    // create a uniform contiguous map
 
106
    RCP<const Map<LO,GO> > map = rcp(new Map<LO,GO>(dim,static_cast<GO>(0),comm,LocallyReplicated) );
 
107
    RCP<MV> mvec = rcp( new MV(map,numVecs,true) );
 
108
    bool res = Belos::TestMultiVecTraits<Scalar,MV>(MyOM,mvec);
 
109
    TEST_EQUALITY_CONST(res,true);
 
110
    // All procs fail if any proc fails
 
111
    int globalSuccess_int = -1;
 
112
    reduceAll( *comm, Teuchos::REDUCE_SUM, success ? 0 : 1, &globalSuccess_int );
 
113
    TEST_EQUALITY_CONST( globalSuccess_int, 0 );
 
114
  }
 
115
 
 
116
  ////
 
117
  TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( MultiVector, OPTestLocal, LO, GO, Scalar )
 
118
  {
 
119
    typedef MultiVector<Scalar,LO,GO> MV;
 
120
    typedef Operator<Scalar,LO,GO>    OP;
 
121
    const global_size_t dim = 500;
 
122
    const size_t numVecs = 5;
 
123
    // Create an output manager to handle the I/O from the solver
 
124
    RCP<OutputManager<Scalar> > MyOM = rcp( new OutputManager<Scalar>(Warnings,rcpFromRef(out)) );
 
125
    // get a comm
 
126
    RCP<const Comm<int> > comm = getDefaultComm();
182
127
    // create a uniform contiguous map (local)
183
 
    Map<Ordinal> map(dim,ZERO,platform,true);
 
128
    RCP<const Map<LO,GO> > map = rcp( new Map<LO,GO>(dim,static_cast<GO>(0),comm,LocallyReplicated) );
184
129
    // create a CrsMatrix
185
 
    RCP<OP> op = constructTriDiagMatrix<Ordinal,Scalar>(map);
 
130
    RCP<OP> op = constructDiagMatrix<Scalar,LO,GO>(map);
186
131
    // create a multivector
187
132
    RCP<MV> mvec = rcp( new MV(map,numVecs,true) );
188
133
    bool res = Belos::TestOperatorTraits<Scalar,MV,OP>(MyOM,mvec,op);
194
139
  }
195
140
 
196
141
  ////
197
 
  TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL( MultiVector, OPTestDist, Ordinal, Scalar )
 
142
  TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( MultiVector, OPTestDist, LO, GO, Scalar )
198
143
  {
199
 
    typedef Tpetra::MultiVector<Ordinal,Scalar> MV;
200
 
    typedef Tpetra::Operator<Ordinal,Scalar>    OP;
201
 
    // const Ordinal dim = 500;
202
 
    const Ordinal dim = 10;
203
 
    const Ordinal numVecs = 5;
204
 
    const Ordinal ZERO = OrdinalTraits<Ordinal>::zero();
 
144
    typedef MultiVector<Scalar,LO,GO> MV;
 
145
    typedef Operator<Scalar,LO,GO>    OP;
 
146
    const global_size_t dim = 500;
 
147
    const size_t numVecs = 5;
205
148
    // Create an output manager to handle the I/O from the solver
206
 
    RCP<OutputManager<Scalar> > MyOM = rcp( new OutputManager<Scalar>(Warnings,rcp(&out,false)) );
207
 
    // create a platform  
208
 
    const Platform<Ordinal> & platform = *(getDefaultPlatform<Ordinal>());
209
 
    // create a comm  
210
 
    RCP<Comm<Ordinal> > comm = platform.createComm();
 
149
    RCP<OutputManager<Scalar> > MyOM = rcp( new OutputManager<Scalar>(Warnings,rcpFromRef(out)) );
 
150
    // get a comm
 
151
    RCP<const Comm<int> > comm = getDefaultComm();
211
152
    // create a uniform contiguous map
212
 
    Map<Ordinal> map(dim,ZERO,platform);
 
153
    RCP<const Map<LO,GO> > map = rcp( new Map<LO,GO>(dim,static_cast<GO>(0),comm) );
213
154
    // create a CrsMatrix
214
 
    RCP<OP> op = constructTriDiagMatrix<Ordinal,Scalar>(map);
 
155
    RCP<OP> op = constructDiagMatrix<Scalar,LO,GO>(map);
215
156
    // create a multivector
216
157
    RCP<MV> mvec = rcp( new MV(map,numVecs,true) );
217
158
    bool res = Belos::TestOperatorTraits<Scalar,MV,OP>(MyOM,mvec,op);
227
168
  //
228
169
 
229
170
#ifdef HAVE_TEUCHOS_COMPLEX
230
 
#  define UNIT_TEST_GROUP_ORDINAL_COMPLEX_FLOAT(ORDINAL)\
 
171
#  define UNIT_TEST_GROUP_ORDINAL_COMPLEX_FLOAT(LO, GO)\
231
172
     typedef std::complex<float> ComplexFloat; \
232
 
     UNIT_TEST_GROUP_ORDINAL_SCALAR(ORDINAL, ComplexFloat)
233
 
#  define UNIT_TEST_GROUP_ORDINAL_COMPLEX_DOUBLE(ORDINAL)\
 
173
     UNIT_TEST_GROUP_ORDINAL_SCALAR(LO, GO, ComplexFloat)
 
174
#  define UNIT_TEST_GROUP_ORDINAL_COMPLEX_DOUBLE(LO, GO)\
234
175
     typedef std::complex<double> ComplexDouble; \
235
 
     UNIT_TEST_GROUP_ORDINAL_SCALAR(ORDINAL, ComplexDouble)
 
176
     UNIT_TEST_GROUP_ORDINAL_SCALAR(LO, GO, ComplexDouble)
236
177
#else
237
 
#  define UNIT_TEST_GROUP_ORDINAL_COMPLEX_FLOAT(ORDINAL)
238
 
#  define UNIT_TEST_GROUP_ORDINAL_COMPLEX_DOUBLE(ORDINAL)
 
178
#  define UNIT_TEST_GROUP_ORDINAL_COMPLEX_FLOAT(LO, GO)
 
179
#  define UNIT_TEST_GROUP_ORDINAL_COMPLEX_DOUBLE(LO, GO)
239
180
#endif
240
181
 
241
182
  // Uncomment this for really fast development cycles but make sure to comment
242
183
  // it back again before checking in so that we can test all the types.
243
 
  #define FAST_DEVELOPMENT_UNIT_TEST_BUILD
244
 
 
245
 
#define UNIT_TEST_GROUP_ORDINAL_SCALAR( ORDINAL, SCALAR ) \
246
 
      TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( MultiVector, MVTestDist, ORDINAL, SCALAR ) \
247
 
      TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( MultiVector, MVTestLocal, ORDINAL, SCALAR ) \
248
 
      TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( MultiVector, OPTestDist, ORDINAL, SCALAR ) \
249
 
      TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT( MultiVector, OPTestLocal, ORDINAL, SCALAR )
 
184
  // #define FAST_DEVELOPMENT_UNIT_TEST_BUILD
 
185
 
 
186
#define UNIT_TEST_GROUP_ORDINAL_SCALAR( LO, GO, SCALAR ) \
 
187
      TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( MultiVector, MVTestDist, LO, GO, SCALAR ) \
 
188
      TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( MultiVector, MVTestLocal, LO, GO, SCALAR ) \
 
189
      TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( MultiVector, OPTestDist, LO, GO, SCALAR ) \
 
190
      TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( MultiVector, OPTestLocal, LO, GO, SCALAR )
 
191
 
 
192
#define UNIT_TEST_GROUP_ORDINAL( ORDINAL ) \
 
193
    UNIT_TEST_GROUP_ORDINAL_ORDINAL( ORDINAL, ORDINAL )
250
194
 
251
195
# ifdef FAST_DEVELOPMENT_UNIT_TEST_BUILD
252
 
#    define UNIT_TEST_GROUP_ORDINAL( ORDINAL ) \
253
 
         /*UNIT_TEST_GROUP_ORDINAL_COMPLEX_FLOAT(ORDINAL)*/ \
254
 
         UNIT_TEST_GROUP_ORDINAL_SCALAR(ORDINAL, double)
 
196
#    define UNIT_TEST_GROUP_ORDINAL_ORDINAL( LO, GO ) \
 
197
         UNIT_TEST_GROUP_ORDINAL_COMPLEX_FLOAT(LO, GO) \
 
198
         UNIT_TEST_GROUP_ORDINAL_SCALAR(LO, GO, double)
 
199
 
255
200
     UNIT_TEST_GROUP_ORDINAL(int)
256
201
# else // not FAST_DEVELOPMENT_UNIT_TEST_BUILD
257
202
 
258
 
#    define UNIT_TEST_GROUP_ORDINAL( ORDINAL ) \
259
 
         UNIT_TEST_GROUP_ORDINAL_SCALAR(ORDINAL, char) \
260
 
         UNIT_TEST_GROUP_ORDINAL_SCALAR(ORDINAL, int) \
261
 
         UNIT_TEST_GROUP_ORDINAL_SCALAR(ORDINAL, float) \
262
 
         UNIT_TEST_GROUP_ORDINAL_SCALAR(ORDINAL, double) \
263
 
         UNIT_TEST_GROUP_ORDINAL_COMPLEX_FLOAT(ORDINAL) \
264
 
         UNIT_TEST_GROUP_ORDINAL_COMPLEX_DOUBLE(ORDINAL)
265
 
     UNIT_TEST_GROUP_ORDINAL(int)
 
203
#    define UNIT_TEST_GROUP_ORDINAL_ORDINAL( LO, GO ) \
 
204
         UNIT_TEST_GROUP_ORDINAL_SCALAR(LO, GO, float) \
 
205
         UNIT_TEST_GROUP_ORDINAL_SCALAR(LO, GO, double) \
 
206
         UNIT_TEST_GROUP_ORDINAL_COMPLEX_FLOAT(LO, GO) \
 
207
         UNIT_TEST_GROUP_ORDINAL_COMPLEX_DOUBLE(LO, GO)
266
208
 
267
209
     typedef short int ShortInt;
268
210
     UNIT_TEST_GROUP_ORDINAL(ShortInt)
 
211
 
 
212
     UNIT_TEST_GROUP_ORDINAL(int)
 
213
 
269
214
     typedef long int LongInt;
270
 
     UNIT_TEST_GROUP_ORDINAL(LongInt)
 
215
     UNIT_TEST_GROUP_ORDINAL_ORDINAL( int, LongInt )
271
216
#    ifdef HAVE_TEUCHOS_LONG_LONG_INT
272
217
        typedef long long int LongLongInt;
273
 
        UNIT_TEST_GROUP_ORDINAL(LongLongInt)
 
218
        UNIT_TEST_GROUP_ORDINAL_ORDINAL( int,LongLongInt)
274
219
#    endif
275
220
 
276
221
# endif // FAST_DEVELOPMENT_UNIT_TEST_BUILD