~ubuntu-branches/ubuntu/trusty/deal.ii/trusty

« back to all changes in this revision

Viewing changes to lac/include/lac/trilinos_sparsity_pattern.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam C. Powell, IV, Adam C. Powell, IV, Denis Barbier
  • Date: 2010-07-29 13:47:01 UTC
  • mfrom: (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100729134701-akb8jb3stwge8tcm
Tags: 6.3.1-1
[ Adam C. Powell, IV ]
* Changed to source format 3.0 (quilt).
* Changed maintainer to debian-science with Adam Powell as uploader.
* Added source lintian overrides about Adam Powell's name.
* Added Vcs info on git repository.
* Bumped Standards-Version.
* Changed stamp-patch to patch target and fixed its application criterion.
* Moved make_dependencies and expand_instantiations to a versioned directory
  to avoid shlib package conflicts.

[ Denis Barbier ]
* New upstream release (closes: #562332).
  + Added libtbb support.
  + Forward-ported all patches.
* Updates for new PETSc version, including workaround for different versions
  of petsc and slepc.
* Add debian/watch.
* Update to debhelper 7.
* Added pdebuild patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//---------------------------------------------------------------------------
2
 
//    $Id: trilinos_sparsity_pattern.h 18724 2009-04-23 23:06:37Z bangerth $
 
2
//    $Id: trilinos_sparsity_pattern.h 21128 2010-05-14 13:34:33Z kronbichler $
3
3
//    Version: $Name$
4
4
//
5
 
//    Copyright (C) 2008, 2009 by the deal.II authors
 
5
//    Copyright (C) 2008, 2009, 2010 by the deal.II authors
6
6
//
7
7
//    This file is subject to QPL and may not be  distributed
8
8
//    without copyright and license information. Please refer
15
15
 
16
16
 
17
17
#include <base/config.h>
18
 
#include <base/subscriptor.h>
19
 
#include <lac/exceptions.h>
20
 
 
21
 
#include <base/std_cxx1x/shared_ptr.h>
22
 
#include <vector>
23
 
#include <cmath>
24
 
#include <memory>
25
18
 
26
19
#ifdef DEAL_II_USE_TRILINOS
27
20
 
 
21
#  include <base/subscriptor.h>
 
22
#  include <base/index_set.h>
 
23
#  include <lac/exceptions.h>
 
24
 
 
25
#  include <vector>
 
26
#  include <cmath>
 
27
#  include <memory>
 
28
 
 
29
#  include <base/std_cxx1x/shared_ptr.h>
 
30
#  include <boost/scoped_ptr.hpp>
 
31
 
28
32
#  include <Epetra_FECrsGraph.h>
29
33
#  include <Epetra_Map.h>
30
34
#  ifdef DEAL_II_COMPILER_SUPPORTS_MPI
107
111
                            << " of a distributed sparsity pattern, "
108
112
                            << " but only rows " << arg2 << " through " << arg3
109
113
                            << " are stored locally and can be accessed.");
110
 
            
 
114
 
111
115
          private:
112
116
                                       /**
113
117
                                        * The matrix accessed.
150
154
                                        * this data if necessary.
151
155
                                        */
152
156
            std_cxx1x::shared_ptr<const std::vector<unsigned int> > colnum_cache;
153
 
            
 
157
 
154
158
                                       /**
155
159
                                        * Discard the old row caches
156
160
                                        * (they may still be used by
167
171
                                        */
168
172
            friend class const_iterator;
169
173
        };
170
 
        
 
174
 
171
175
      public:
172
 
          
 
176
 
173
177
                                       /**
174
178
                                        * Constructor. Create an
175
179
                                        * iterator into the matrix @p
176
180
                                        * matrix for the given row and
177
181
                                        * the index within it.
178
 
                                        */ 
 
182
                                        */
179
183
        const_iterator (const SparsityPattern *sparsity_pattern,
180
184
                        const unsigned int     row,
181
185
                        const unsigned int     index);
182
 
          
 
186
 
183
187
                                       /**
184
188
                                        * Prefix increment.
185
189
                                        */
230
234
                        << "Attempt to access element " << arg2
231
235
                        << " of row " << arg1
232
236
                        << " which doesn't have that many elements.");
233
 
        
 
237
 
234
238
      private:
235
239
                                       /**
236
240
                                        * Store an object of the
240
244
 
241
245
        friend class TrilinosWrappers::SparsityPattern;
242
246
    };
243
 
    
 
247
 
244
248
  }
245
 
  
246
 
  
 
249
 
 
250
 
247
251
/**
248
252
 * This class implements a wrapper class to use the Trilinos distributed
249
253
 * sparsity pattern class Epetra_FECrsGraph. This class is designed to be
250
 
 * used for construction of parallel Trilinos matrices. The functionality of
 
254
 * used for construction of %parallel Trilinos matrices. The functionality of
251
255
 * this class is modeled after the existing sparsity pattern classes, with
252
 
 * the difference that this class can work fully in parallel according to a
 
256
 * the difference that this class can work fully in %parallel according to a
253
257
 * partitioning of the sparsity pattern rows.
254
258
 *
255
259
 * This class has many similarities to the compressed sparsity pattern
259
263
 * previously reserved for it. However, it also has a method
260
264
 * SparsityPattern::compress(), that finalizes the pattern and enables its
261
265
 * use with Trilinos sparse matrices.
262
 
 * 
 
266
 *
263
267
 * @ingroup TrilinosWrappers
264
268
 * @ingroup Sparsity
265
269
 * @author Martin Kronbichler, 2008
273
277
                                        * iterator class.
274
278
                                        */
275
279
      typedef SparsityPatternIterators::const_iterator const_iterator;
276
 
      
 
280
 
277
281
/**
278
 
 * @name Constructors and initalization.
 
282
 * @name Basic constructors and initalization.
279
283
 */
280
284
//@{
281
285
                                       /**
286
290
      SparsityPattern ();
287
291
 
288
292
                                       /**
289
 
                                        * Constructor for a square sparsity
290
 
                                        * pattern using an Epetra_Map and
291
 
                                        * the number of nonzero entries in
292
 
                                        * the rows of the sparsity
293
 
                                        * pattern. Note that this number
294
 
                                        * does not need to be exact, and it
295
 
                                        * is even allowed that the actual
296
 
                                        * sparsity structure has more
297
 
                                        * nonzero entries than specified in
298
 
                                        * the constructor. However it is
299
 
                                        * still advantageous to provide good
300
 
                                        * estimates here since this will
301
 
                                        * considerably increase the
302
 
                                        * performance when creating the
303
 
                                        * sparsity pattern.
304
 
                                        */
305
 
      SparsityPattern (const Epetra_Map   &InputMap,
306
 
                       const unsigned int  n_entries_per_row = 0);
307
 
 
308
 
                                       /**
309
 
                                        * Same as before, but now use the
310
 
                                        * exact number of nonzeros in each m
311
 
                                        * row. Since we know the number of
312
 
                                        * elements in the sparsity pattern
313
 
                                        * exactly in this case, we can
314
 
                                        * already allocate the right amount
315
 
                                        * of memory, which makes the
316
 
                                        * creation process by the respective
317
 
                                        * SparsityPattern::reinit call
318
 
                                        * considerably faster. However, this
319
 
                                        * is a rather unusual situation,
320
 
                                        * since knowing the number of
321
 
                                        * entries in each row is usually
322
 
                                        * connected to knowing the indices
323
 
                                        * of nonzero entries, which the
324
 
                                        * sparsity pattern is designed to
325
 
                                        * describe.
326
 
                                        */
327
 
      SparsityPattern (const Epetra_Map                &InputMap,
328
 
                       const std::vector<unsigned int> &n_entries_per_row);
329
 
 
330
 
                                       /**
331
 
                                        * This constructor is similar to the
332
 
                                        * one above, but it now takes two
333
 
                                        * different Epetra maps for rows and
334
 
                                        * columns. This interface is meant
335
 
                                        * to be used for generating
336
 
                                        * rectangular sparsity pattern,
337
 
                                        * where one map describes the
338
 
                                        * parallel partitioning of the dofs
339
 
                                        * associated with the sparsity
340
 
                                        * pattern rows and the other one of
341
 
                                        * the sparsity pattern columns. Note
342
 
                                        * that there is no real parallelism
343
 
                                        * along the columns &ndash; the
344
 
                                        * processor that owns a certain row
345
 
                                        * always owns all the column
346
 
                                        * elements, no matter how far they
347
 
                                        * might be spread out. The second
348
 
                                        * Epetra_Map is only used to specify
349
 
                                        * the number of columns and for
350
 
                                        * internal arragements when doing
351
 
                                        * matrix-vector products with
352
 
                                        * vectors based on that column map.
353
 
                                        *
354
 
                                        * The number of columns entries
355
 
                                        * per row is specified as the
356
 
                                        * maximum number of entries
357
 
                                        * argument.
358
 
                                        */
359
 
      SparsityPattern (const Epetra_Map   &InputRowMap,
360
 
                       const Epetra_Map   &InputColMap,
361
 
                       const unsigned int  n_entries_per_row = 0);
362
 
 
363
 
                                       /**
364
 
                                        * This constructor is similar to the
365
 
                                        * one above, but it now takes two
366
 
                                        * different Epetra maps for rows and
367
 
                                        * columns. This interface is meant
368
 
                                        * to be used for generating
369
 
                                        * rectangular matrices, where one
370
 
                                        * map specifies the parallel
371
 
                                        * distribution of rows and the
372
 
                                        * second one specifies the
373
 
                                        * distribution of degrees of freedom
374
 
                                        * associated with matrix
375
 
                                        * columns. This second map is
376
 
                                        * however not used for the
377
 
                                        * distribution of the columns
378
 
                                        * themselves &ndash; rather, all
379
 
                                        * column elements of a row are
380
 
                                        * stored on the same processor. The
381
 
                                        * vector <tt>n_entries_per_row</tt>
382
 
                                        * specifies the number of entries in
383
 
                                        * each row of the newly generated
384
 
                                        * matrix.
385
 
                                        */
386
 
      SparsityPattern (const Epetra_Map                &InputRowMap,
387
 
                       const Epetra_Map                &InputColMap,
388
 
                       const std::vector<unsigned int> &n_entries_per_row);
389
 
 
390
 
                                       /**
391
 
                                        * Generate a sparsity pattern that
392
 
                                        * is completely stored locally,
393
 
                                        * having $m$ rows and $n$ columns. The
394
 
                                        * resulting matrix will be
395
 
                                        * completely stored locally.
396
 
                                        *
397
 
                                        * The number of columns entries per
398
 
                                        * row is specified as the maximum
399
 
                                        * number of entries argument. As
400
 
                                        * above, this does not need to be an
401
 
                                        * accurate number since the entries
402
 
                                        * are allocated dynamically in a
403
 
                                        * similar manner as for the deal.II
404
 
                                        * CompressedSparsityPattern classes,
405
 
                                        * but a good estimate will reduce
406
 
                                        * the setup time of the sparsity
407
 
                                        * pattern.
408
 
                                        */
 
293
                                        * Generate a sparsity pattern that is
 
294
                                        * completely stored locally, having
 
295
                                        * $m$ rows and $n$ columns. The
 
296
                                        * resulting matrix will be completely
 
297
                                        * stored locally, too.
 
298
                                        *
 
299
                                        * It is possible to specify the
 
300
                                        * number of columns entries per row
 
301
                                        * using the optional @p
 
302
                                        * n_entries_per_row
 
303
                                        * argument. However, this value does
 
304
                                        * not need to be accurate or even
 
305
                                        * given at all, since one does
 
306
                                        * usually not have this kind of
 
307
                                        * information before building the
 
308
                                        * sparsity pattern (the usual case
 
309
                                        * when the function
 
310
                                        * DoFTools::make_sparsity_pattern()
 
311
                                        * is called). The entries are
 
312
                                        * allocated dynamically in a similar
 
313
                                        * manner as for the deal.II
 
314
                                        * CompressedSparsityPattern
 
315
                                        * classes. However, a good estimate
 
316
                                        * will reduce the setup time of the
 
317
                                        * sparsity pattern.
 
318
                                        */
409
319
      SparsityPattern (const unsigned int  m,
410
320
                       const unsigned int  n,
411
321
                       const unsigned int  n_entries_per_row = 0);
412
322
 
413
323
                                       /**
414
 
                                        * Generate a sparsity pattern that
415
 
                                        * is completely stored locally,
416
 
                                        * having $m$ rows and $n$ columns. The
417
 
                                        * resulting matrix will be
418
 
                                        * completely stored locally.
 
324
                                        * Generate a sparsity pattern that is
 
325
                                        * completely stored locally, having
 
326
                                        * $m$ rows and $n$ columns. The
 
327
                                        * resulting matrix will be completely
 
328
                                        * stored locally, too.
419
329
                                        *
420
330
                                        * The vector
421
331
                                        * <tt>n_entries_per_row</tt>
422
332
                                        * specifies the number of entries in
423
 
                                        * each row.
 
333
                                        * each row (an information usually
 
334
                                        * not available, though).
424
335
                                        */
425
336
      SparsityPattern (const unsigned int               m,
426
337
                       const unsigned int               n,
431
342
                                        * sparsity pattern to be the same as
432
343
                                        * the input sparsity pattern.
433
344
                                        */
434
 
      SparsityPattern (const SparsityPattern &SP);
 
345
      SparsityPattern (const SparsityPattern &input_sparsity_pattern);
435
346
 
436
347
                                       /**
437
348
                                        * Destructor. Made virtual so that
441
352
      virtual ~SparsityPattern ();
442
353
 
443
354
                                       /**
444
 
                                        * Reinitialization function for
445
 
                                        * generating a square sparsity
446
 
                                        * pattern using an Epetra_Map and
447
 
                                        * the number of nonzero entries in
448
 
                                        * the rows of the sparsity
449
 
                                        * pattern. Note that this number
450
 
                                        * does not need to be exact, and it
451
 
                                        * is even allowed that the actual
452
 
                                        * sparsity structure has more
453
 
                                        * nonzero entries than specified in
454
 
                                        * the constructor. However it is
455
 
                                        * still advantageous to provide good
456
 
                                        * estimates here since this will
457
 
                                        * considerably increase the
458
 
                                        * performance when creating the
459
 
                                        * sparsity pattern.
460
 
                                        *
461
 
                                        * This function does not create any
462
 
                                        * entries by itself, but provides
463
 
                                        * the correct data structures that
464
 
                                        * can be used by the respective
465
 
                                        * add() function.
466
 
                                        */
467
 
      void  
468
 
      reinit (const Epetra_Map   &InputMap,
469
 
              const unsigned int  n_entries_per_row = 0);
470
 
 
471
 
                                       /**
472
 
                                        * Same as before, but now use the
473
 
                                        * exact number of nonzeros in each m
474
 
                                        * row. Since we know the number of
475
 
                                        * elements in the sparsity pattern
476
 
                                        * exactly in this case, we can
477
 
                                        * already allocate the right amount
478
 
                                        * of memory, which makes process of
479
 
                                        * adding entries to the sparsity
480
 
                                        * pattern considerably
481
 
                                        * faster. However, this is a rather
482
 
                                        * unusual situation, since knowing
483
 
                                        * the number of entries in each row
484
 
                                        * is usually connected to knowing
485
 
                                        * the indices of nonzero entries,
486
 
                                        * which the sparsity pattern is
487
 
                                        * designed to describe.
488
 
                                        */
489
 
      void  
490
 
      reinit (const Epetra_Map                &InputMap,
491
 
              const std::vector<unsigned int> &n_entries_per_row);
492
 
 
493
 
                                       /**
494
 
                                        * This reinit function is similar to
495
 
                                        * the one above, but it now takes
496
 
                                        * two different Epetra maps for rows
497
 
                                        * and columns. This interface is
498
 
                                        * meant to be used for generating
499
 
                                        * rectangular sparsity pattern,
500
 
                                        * where one map describes the
501
 
                                        * parallel partitioning of the dofs
502
 
                                        * associated with the sparsity
503
 
                                        * pattern rows and the other one of
504
 
                                        * the sparsity pattern columns. Note
505
 
                                        * that there is no real parallelism
506
 
                                        * along the columns &ndash; the
507
 
                                        * processor that owns a certain row
508
 
                                        * always owns all the column
509
 
                                        * elements, no matter how far they
510
 
                                        * might be spread out. The second
511
 
                                        * Epetra_Map is only used to specify
512
 
                                        * the number of columns and for
513
 
                                        * internal arragements when doing
514
 
                                        * matrix-vector products with
515
 
                                        * vectors based on that column map.
516
 
                                        *
517
 
                                        * The number of columns entries per
518
 
                                        * row is specified by the argument
519
 
                                        * <tt>n_entries_per_row</tt>.
520
 
                                        */
521
 
      void  
522
 
      reinit (const Epetra_Map   &InputRowMap,
523
 
              const Epetra_Map   &InputColMap,
524
 
              const unsigned int  n_entries_per_row = 0);
525
 
 
526
 
                                       /**
527
 
                                        * This reinit function is similar to
528
 
                                        * the one above, but it now takes
529
 
                                        * two different Epetra maps for rows
530
 
                                        * and columns. This interface is
531
 
                                        * meant to be used for generating
532
 
                                        * rectangular matrices, where one
533
 
                                        * map specifies the parallel
534
 
                                        * distribution of rows and the
535
 
                                        * second one specifies the
536
 
                                        * distribution of degrees of freedom
537
 
                                        * associated with matrix
538
 
                                        * columns. This second map is
539
 
                                        * however not used for the
540
 
                                        * distribution of the columns
541
 
                                        * themselves &ndash; rather, all
542
 
                                        * column elements of a row are
543
 
                                        * stored on the same processor. The
544
 
                                        * vector <tt>n_entries_per_row</tt>
545
 
                                        * specifies the number of entries in
546
 
                                        * each row of the newly generated
547
 
                                        * matrix.
548
 
                                        */
549
 
      void  
550
 
      reinit (const Epetra_Map                &InputRowMap,
551
 
              const Epetra_Map                &InputColMap,
552
 
              const std::vector<unsigned int> &n_entries_per_row);
553
 
 
554
 
                                       /**
555
355
                                        * Initialize a sparsity pattern that
556
356
                                        * is completely stored locally,
557
 
                                        * having $m$ rows and $n$ columns. The
558
 
                                        * resulting matrix will be
559
 
                                        * completely stored locally.
 
357
                                        * having $m$ rows and $n$
 
358
                                        * columns. The resulting matrix will
 
359
                                        * be completely stored locally.
560
360
                                        *
561
361
                                        * The number of columns entries per
562
362
                                        * row is specified as the maximum
563
 
                                        * number of entries argument. As
564
 
                                        * above, this does not need to be an
565
 
                                        * accurate number since the entries
566
 
                                        * are allocated dynamically in a
567
 
                                        * similar manner as for the deal.II
 
363
                                        * number of entries argument.  This
 
364
                                        * does not need to be an accurate
 
365
                                        * number since the entries are
 
366
                                        * allocated dynamically in a similar
 
367
                                        * manner as for the deal.II
568
368
                                        * CompressedSparsityPattern classes,
569
369
                                        * but a good estimate will reduce
570
370
                                        * the setup time of the sparsity
571
371
                                        * pattern.
572
372
                                        */
573
 
      void  
 
373
      void
574
374
      reinit (const unsigned int  m,
575
375
              const unsigned int  n,
576
376
              const unsigned int  n_entries_per_row = 0);
587
387
                                        * specifies the number of entries in
588
388
                                        * each row.
589
389
                                        */
590
 
      void  
 
390
      void
591
391
      reinit (const unsigned int               m,
592
392
              const unsigned int               n,
593
393
              const std::vector<unsigned int> &n_entries_per_row);
594
394
 
595
395
                                       /**
596
 
                                        * Reinit function. Takes one of the
597
 
                                        * deal.II sparsity patterns and a
598
 
                                        * parallel partitioning of the rows
599
 
                                        * and columns for initializing the
600
 
                                        * current Trilinos sparsity pattern.
601
 
                                        */
602
 
      template<typename SparsityType>
603
 
      void  
604
 
      reinit (const Epetra_Map   &InputRowMap,
605
 
              const Epetra_Map   &InputColMap,
606
 
              const SparsityType &SP);
607
 
 
608
 
                                       /**
609
 
                                        * Reinit function. Takes one of the
610
 
                                        * deal.II sparsity patterns and a
611
 
                                        * parallel partitioning of the rows
612
 
                                        * and columns for initializing the
613
 
                                        * current Trilinos sparsity pattern.
614
 
                                        */
615
 
      template<typename SparsityType>
616
 
      void  
617
 
      reinit (const Epetra_Map   &InputMap,
618
 
              const SparsityType &SP);
619
 
 
620
 
                                       /**
621
396
                                        * Copy function. Sets the calling
622
397
                                        * sparsity pattern to be the same as
623
398
                                        * the input sparsity pattern.
624
399
                                        */
625
 
      void  
626
 
      copy_from (const SparsityPattern &SP);
 
400
      void
 
401
      copy_from (const SparsityPattern &input_sparsity_pattern);
627
402
 
628
403
                                       /**
629
404
                                        * Copy function from one of the
633
408
                                        * and columns.
634
409
                                        */
635
410
      template<typename SparsityType>
636
 
      void  
637
 
      copy_from (const SparsityType &SP);
 
411
      void
 
412
      copy_from (const SparsityType &nontrilinos_sparsity_pattern);
 
413
 
 
414
                                       /**
 
415
                                        * Copy operator. This operation is
 
416
                                        * only allowed for empty objects, to
 
417
                                        * avoid potentially very costly
 
418
                                        * operations automatically
 
419
                                        * synthesized by the compiler. Use
 
420
                                        * copy_from() instead if you know
 
421
                                        * that you really want to copy a
 
422
                                        * sparsity pattern with non-trivial
 
423
                                        * content.
 
424
                                        */
 
425
      SparsityPattern & operator = (const SparsityPattern &input_sparsity_pattern);
638
426
 
639
427
                                       /**
640
 
                                        * Release all memory and
641
 
                                        * return to a state just like
642
 
                                        * after having called the
643
 
                                        * default constructor.
 
428
                                        * Release all memory and return to a
 
429
                                        * state just like after having
 
430
                                        * called the default constructor.
644
431
                                        *
645
 
                                        * This is a
646
 
                                        * collective operation that
647
 
                                        * needs to be called on all
 
432
                                        * This is a collective operation
 
433
                                        * that needs to be called on all
648
434
                                        * processors in order to avoid a
649
435
                                        * dead lock.
650
436
                                        */
656
442
                                        * function compresses the sparsity
657
443
                                        * pattern and allows the resulting
658
444
                                        * pattern to be used for actually
659
 
                                        * generating a matrix. This function
660
 
                                        * also exchanges non-local data that
 
445
                                        * generating a (Trilinos-based)
 
446
                                        * matrix. This function also
 
447
                                        * exchanges non-local data that
661
448
                                        * might have accumulated during the
662
449
                                        * addition of new elements. This
663
450
                                        * function must therefore be called
669
456
      void compress ();
670
457
//@}
671
458
/**
 
459
 * @name Constructors and initialization using an Epetra_Map description
 
460
 */
 
461
//@{
 
462
 
 
463
                                       /**
 
464
                                        * Constructor for a square sparsity
 
465
                                        * pattern using an Epetra_map for
 
466
                                        * the description of the %parallel
 
467
                                        * partitioning. Moreover, the number
 
468
                                        * of nonzero entries in the rows of
 
469
                                        * the sparsity pattern can be
 
470
                                        * specified. Note that this number
 
471
                                        * does not need to be exact, and it
 
472
                                        * is allowed that the actual
 
473
                                        * sparsity structure has more
 
474
                                        * nonzero entries than specified in
 
475
                                        * the constructor (the usual case
 
476
                                        * when the function
 
477
                                        * DoFTools::make_sparsity_pattern()
 
478
                                        * is called). However it is still
 
479
                                        * advantageous to provide good
 
480
                                        * estimates here since a good value
 
481
                                        * will avoid repeated allocation of
 
482
                                        * memory, which considerably
 
483
                                        * increases the performance when
 
484
                                        * creating the sparsity pattern.
 
485
                                        */
 
486
      SparsityPattern (const Epetra_Map   &parallel_partitioning,
 
487
                       const unsigned int  n_entries_per_row = 0);
 
488
 
 
489
                                       /**
 
490
                                        * Same as before, but now use the
 
491
                                        * exact number of nonzeros in each m
 
492
                                        * row. Since we know the number of
 
493
                                        * elements in the sparsity pattern
 
494
                                        * exactly in this case, we can
 
495
                                        * already allocate the right amount
 
496
                                        * of memory, which makes the
 
497
                                        * creation process by the respective
 
498
                                        * SparsityPattern::reinit call
 
499
                                        * considerably faster. However, this
 
500
                                        * is a rather unusual situation,
 
501
                                        * since knowing the number of
 
502
                                        * entries in each row is usually
 
503
                                        * connected to knowing the indices
 
504
                                        * of nonzero entries, which the
 
505
                                        * sparsity pattern is designed to
 
506
                                        * describe.
 
507
                                        */
 
508
      SparsityPattern (const Epetra_Map                &parallel_partitioning,
 
509
                       const std::vector<unsigned int> &n_entries_per_row);
 
510
 
 
511
                                       /**
 
512
                                        * This constructor is similar to the
 
513
                                        * one above, but it now takes two
 
514
                                        * different Epetra maps for rows and
 
515
                                        * columns. This interface is meant to
 
516
                                        * be used for generating rectangular
 
517
                                        * sparsity pattern, where one map
 
518
                                        * describes the %parallel partitioning
 
519
                                        * of the dofs associated with the
 
520
                                        * sparsity pattern rows and the other
 
521
                                        * one of the sparsity pattern
 
522
                                        * columns. Note that there is no real
 
523
                                        * parallelism along the columns
 
524
                                        * &ndash; the processor that owns a
 
525
                                        * certain row always owns all the
 
526
                                        * column elements, no matter how far
 
527
                                        * they might be spread out. The second
 
528
                                        * Epetra_Map is only used to specify
 
529
                                        * the number of columns and for
 
530
                                        * specifying the correct domain space
 
531
                                        * when performing matrix-vector
 
532
                                        * products with vectors based on the
 
533
                                        * same column map.
 
534
                                        *
 
535
                                        * The number of columns entries per
 
536
                                        * row is specified as the maximum
 
537
                                        * number of entries argument.
 
538
                                        */
 
539
      SparsityPattern (const Epetra_Map   &row_parallel_partitioning,
 
540
                       const Epetra_Map   &col_parallel_partitioning,
 
541
                       const unsigned int  n_entries_per_row = 0);
 
542
 
 
543
                                       /**
 
544
                                        * This constructor is similar to the
 
545
                                        * one above, but it now takes two
 
546
                                        * different Epetra maps for rows and
 
547
                                        * columns. This interface is meant to
 
548
                                        * be used for generating rectangular
 
549
                                        * matrices, where one map specifies
 
550
                                        * the %parallel distribution of rows
 
551
                                        * and the second one specifies the
 
552
                                        * distribution of degrees of freedom
 
553
                                        * associated with matrix columns. This
 
554
                                        * second map is however not used for
 
555
                                        * the distribution of the columns
 
556
                                        * themselves &ndash; rather, all
 
557
                                        * column elements of a row are stored
 
558
                                        * on the same processor. The vector
 
559
                                        * <tt>n_entries_per_row</tt> specifies
 
560
                                        * the number of entries in each row of
 
561
                                        * the newly generated matrix.
 
562
                                        */
 
563
      SparsityPattern (const Epetra_Map                &row_parallel_partitioning,
 
564
                       const Epetra_Map                &col_parallel_partitioning,
 
565
                       const std::vector<unsigned int> &n_entries_per_row);
 
566
 
 
567
                                       /**
 
568
                                        * Reinitialization function for
 
569
                                        * generating a square sparsity pattern
 
570
                                        * using an Epetra_Map for the
 
571
                                        * description of the %parallel
 
572
                                        * partitioning and the number of
 
573
                                        * nonzero entries in the rows of the
 
574
                                        * sparsity pattern. Note that this
 
575
                                        * number does not need to be exact,
 
576
                                        * and it is even allowed that the
 
577
                                        * actual sparsity structure has more
 
578
                                        * nonzero entries than specified in
 
579
                                        * the constructor. However it is still
 
580
                                        * advantageous to provide good
 
581
                                        * estimates here since this will
 
582
                                        * considerably increase the
 
583
                                        * performance when creating the
 
584
                                        * sparsity pattern.
 
585
                                        *
 
586
                                        * This function does not create any
 
587
                                        * entries by itself, but provides
 
588
                                        * the correct data structures that
 
589
                                        * can be used by the respective
 
590
                                        * add() function.
 
591
                                        */
 
592
      void
 
593
      reinit (const Epetra_Map   &parallel_partitioning,
 
594
              const unsigned int  n_entries_per_row = 0);
 
595
 
 
596
                                       /**
 
597
                                        * Same as before, but now use the
 
598
                                        * exact number of nonzeros in each m
 
599
                                        * row. Since we know the number of
 
600
                                        * elements in the sparsity pattern
 
601
                                        * exactly in this case, we can
 
602
                                        * already allocate the right amount
 
603
                                        * of memory, which makes process of
 
604
                                        * adding entries to the sparsity
 
605
                                        * pattern considerably
 
606
                                        * faster. However, this is a rather
 
607
                                        * unusual situation, since knowing
 
608
                                        * the number of entries in each row
 
609
                                        * is usually connected to knowing
 
610
                                        * the indices of nonzero entries,
 
611
                                        * which the sparsity pattern is
 
612
                                        * designed to describe.
 
613
                                        */
 
614
      void
 
615
      reinit (const Epetra_Map                &parallel_partitioning,
 
616
              const std::vector<unsigned int> &n_entries_per_row);
 
617
 
 
618
                                       /**
 
619
                                        * This reinit function is similar to
 
620
                                        * the one above, but it now takes
 
621
                                        * two different Epetra maps for rows
 
622
                                        * and columns. This interface is
 
623
                                        * meant to be used for generating
 
624
                                        * rectangular sparsity pattern,
 
625
                                        * where one map describes the
 
626
                                        * %parallel partitioning of the dofs
 
627
                                        * associated with the sparsity
 
628
                                        * pattern rows and the other one of
 
629
                                        * the sparsity pattern columns. Note
 
630
                                        * that there is no real parallelism
 
631
                                        * along the columns &ndash; the
 
632
                                        * processor that owns a certain row
 
633
                                        * always owns all the column
 
634
                                        * elements, no matter how far they
 
635
                                        * might be spread out. The second
 
636
                                        * Epetra_Map is only used to specify
 
637
                                        * the number of columns and for
 
638
                                        * internal arragements when doing
 
639
                                        * matrix-vector products with
 
640
                                        * vectors based on that column map.
 
641
                                        *
 
642
                                        * The number of columns entries per
 
643
                                        * row is specified by the argument
 
644
                                        * <tt>n_entries_per_row</tt>.
 
645
                                        */
 
646
      void
 
647
      reinit (const Epetra_Map   &row_parallel_partitioning,
 
648
              const Epetra_Map   &col_parallel_partitioning,
 
649
              const unsigned int  n_entries_per_row = 0);
 
650
 
 
651
                                       /**
 
652
                                        * This reinit function is similar to
 
653
                                        * the one above, but it now takes
 
654
                                        * two different Epetra maps for rows
 
655
                                        * and columns. This interface is
 
656
                                        * meant to be used for generating
 
657
                                        * rectangular matrices, where one
 
658
                                        * map specifies the %parallel
 
659
                                        * distribution of rows and the
 
660
                                        * second one specifies the
 
661
                                        * distribution of degrees of freedom
 
662
                                        * associated with matrix
 
663
                                        * columns. This second map is
 
664
                                        * however not used for the
 
665
                                        * distribution of the columns
 
666
                                        * themselves &ndash; rather, all
 
667
                                        * column elements of a row are
 
668
                                        * stored on the same processor. The
 
669
                                        * vector <tt>n_entries_per_row</tt>
 
670
                                        * specifies the number of entries in
 
671
                                        * each row of the newly generated
 
672
                                        * matrix.
 
673
                                        */
 
674
      void
 
675
      reinit (const Epetra_Map                &row_parallel_partitioning,
 
676
              const Epetra_Map                &col_parallel_partitioning,
 
677
              const std::vector<unsigned int> &n_entries_per_row);
 
678
 
 
679
                                       /**
 
680
                                        * Reinit function. Takes one of the
 
681
                                        * deal.II sparsity patterns and a
 
682
                                        * %parallel partitioning of the rows
 
683
                                        * and columns for initializing the
 
684
                                        * current Trilinos sparsity
 
685
                                        * pattern. The optional argument @p
 
686
                                        * exchange_data can be used for
 
687
                                        * reinitialization with a sparsity
 
688
                                        * pattern that is not fully
 
689
                                        * constructed. This feature is only
 
690
                                        * implemented for input sparsity
 
691
                                        * patterns of type
 
692
                                        * CompressedSimpleSparsityPattern.
 
693
                                        */
 
694
      template<typename SparsityType>
 
695
      void
 
696
      reinit (const Epetra_Map   &row_parallel_partitioning,
 
697
              const Epetra_Map   &col_parallel_partitioning,
 
698
              const SparsityType &nontrilinos_sparsity_pattern,
 
699
              const bool          exchange_data = false);
 
700
 
 
701
                                       /**
 
702
                                        * Reinit function. Takes one of the
 
703
                                        * deal.II sparsity patterns and a
 
704
                                        * %parallel partitioning of the rows
 
705
                                        * and columns for initializing the
 
706
                                        * current Trilinos sparsity
 
707
                                        * pattern. The optional argument @p
 
708
                                        * exchange_data can be used for
 
709
                                        * reinitialization with a sparsity
 
710
                                        * pattern that is not fully
 
711
                                        * constructed. This feature is only
 
712
                                        * implemented for input sparsity
 
713
                                        * patterns of type
 
714
                                        * CompressedSimpleSparsityPattern.
 
715
                                        */
 
716
      template<typename SparsityType>
 
717
      void
 
718
      reinit (const Epetra_Map   &parallel_partitioning,
 
719
              const SparsityType &nontrilinos_sparsity_pattern,
 
720
              const bool          exchange_data = false);
 
721
//@}
 
722
/**
 
723
 * @name Constructors and initialization using an IndexSet description
 
724
 */
 
725
//@{
 
726
 
 
727
                                       /**
 
728
                                        * Constructor for a square sparsity
 
729
                                        * pattern using an IndexSet and an
 
730
                                        * MPI communicator for the
 
731
                                        * description of the %parallel
 
732
                                        * partitioning. Moreover, the number
 
733
                                        * of nonzero entries in the rows of
 
734
                                        * the sparsity pattern can be
 
735
                                        * specified. Note that this number
 
736
                                        * does not need to be exact, and it
 
737
                                        * is even allowed that the actual
 
738
                                        * sparsity structure has more
 
739
                                        * nonzero entries than specified in
 
740
                                        * the constructor. However it is
 
741
                                        * still advantageous to provide good
 
742
                                        * estimates here since a good value
 
743
                                        * will avoid repeated allocation of
 
744
                                        * memory, which considerably
 
745
                                        * increases the performance when
 
746
                                        * creating the sparsity pattern.
 
747
                                        */
 
748
      SparsityPattern (const IndexSet     &parallel_partitioning,
 
749
                       const MPI_Comm     &communicator = MPI_COMM_WORLD,
 
750
                       const unsigned int  n_entries_per_row = 0);
 
751
 
 
752
                                       /**
 
753
                                        * Same as before, but now use the
 
754
                                        * exact number of nonzeros in each m
 
755
                                        * row. Since we know the number of
 
756
                                        * elements in the sparsity pattern
 
757
                                        * exactly in this case, we can
 
758
                                        * already allocate the right amount
 
759
                                        * of memory, which makes the
 
760
                                        * creation process by the respective
 
761
                                        * SparsityPattern::reinit call
 
762
                                        * considerably faster. However, this
 
763
                                        * is a rather unusual situation,
 
764
                                        * since knowing the number of
 
765
                                        * entries in each row is usually
 
766
                                        * connected to knowing the indices
 
767
                                        * of nonzero entries, which the
 
768
                                        * sparsity pattern is designed to
 
769
                                        * describe.
 
770
                                        */
 
771
      SparsityPattern (const IndexSet                  &parallel_partitioning,
 
772
                       const MPI_Comm                  &communicator,
 
773
                       const std::vector<unsigned int> &n_entries_per_row);
 
774
 
 
775
                                       /**
 
776
                                        * This constructor is similar to the
 
777
                                        * one above, but it now takes two
 
778
                                        * different index sets to describe the
 
779
                                        * %parallel partitioning of rows and
 
780
                                        * columns. This interface is meant to
 
781
                                        * be used for generating rectangular
 
782
                                        * sparsity pattern. Note that there is
 
783
                                        * no real parallelism along the
 
784
                                        * columns &ndash; the processor that
 
785
                                        * owns a certain row always owns all
 
786
                                        * the column elements, no matter how
 
787
                                        * far they might be spread out. The
 
788
                                        * second Epetra_Map is only used to
 
789
                                        * specify the number of columns and
 
790
                                        * for internal arragements when doing
 
791
                                        * matrix-vector products with vectors
 
792
                                        * based on that column map.
 
793
                                        *
 
794
                                        * The number of columns entries per
 
795
                                        * row is specified as the maximum
 
796
                                        * number of entries argument.
 
797
                                        */
 
798
      SparsityPattern (const IndexSet     &row_parallel_partitioning,
 
799
                       const IndexSet     &col_parallel_partitioning,
 
800
                       const MPI_Comm     &communicator = MPI_COMM_WORLD,
 
801
                       const unsigned int  n_entries_per_row = 0);
 
802
 
 
803
                                       /**
 
804
                                        * This constructor is similar to the
 
805
                                        * one above, but it now takes two
 
806
                                        * different index sets for rows and
 
807
                                        * columns. This interface is meant to
 
808
                                        * be used for generating rectangular
 
809
                                        * matrices, where one map specifies
 
810
                                        * the %parallel distribution of rows
 
811
                                        * and the second one specifies the
 
812
                                        * distribution of degrees of freedom
 
813
                                        * associated with matrix columns. This
 
814
                                        * second map is however not used for
 
815
                                        * the distribution of the columns
 
816
                                        * themselves &ndash; rather, all
 
817
                                        * column elements of a row are stored
 
818
                                        * on the same processor. The vector
 
819
                                        * <tt>n_entries_per_row</tt> specifies
 
820
                                        * the number of entries in each row of
 
821
                                        * the newly generated matrix.
 
822
                                        */
 
823
      SparsityPattern (const IndexSet                  &row_parallel_partitioning,
 
824
                       const IndexSet                  &col_parallel_partitioning,
 
825
                       const MPI_Comm                  &communicator,
 
826
                       const std::vector<unsigned int> &n_entries_per_row);
 
827
 
 
828
                                       /**
 
829
                                        * Reinitialization function for
 
830
                                        * generating a square sparsity
 
831
                                        * pattern using an IndexSet and an
 
832
                                        * MPI communicator for the
 
833
                                        * description of the %parallel
 
834
                                        * partitioning and the number of
 
835
                                        * nonzero entries in the rows of the
 
836
                                        * sparsity pattern. Note that this
 
837
                                        * number does not need to be exact,
 
838
                                        * and it is even allowed that the
 
839
                                        * actual sparsity structure has more
 
840
                                        * nonzero entries than specified in
 
841
                                        * the constructor. However it is
 
842
                                        * still advantageous to provide good
 
843
                                        * estimates here since this will
 
844
                                        * considerably increase the
 
845
                                        * performance when creating the
 
846
                                        * sparsity pattern.
 
847
                                        *
 
848
                                        * This function does not create any
 
849
                                        * entries by itself, but provides
 
850
                                        * the correct data structures that
 
851
                                        * can be used by the respective
 
852
                                        * add() function.
 
853
                                        */
 
854
      void
 
855
      reinit (const IndexSet     &parallel_partitioning,
 
856
              const MPI_Comm     &communicator = MPI_COMM_WORLD,
 
857
              const unsigned int  n_entries_per_row = 0);
 
858
 
 
859
                                       /**
 
860
                                        * Same as before, but now use the
 
861
                                        * exact number of nonzeros in each m
 
862
                                        * row. Since we know the number of
 
863
                                        * elements in the sparsity pattern
 
864
                                        * exactly in this case, we can
 
865
                                        * already allocate the right amount
 
866
                                        * of memory, which makes process of
 
867
                                        * adding entries to the sparsity
 
868
                                        * pattern considerably
 
869
                                        * faster. However, this is a rather
 
870
                                        * unusual situation, since knowing
 
871
                                        * the number of entries in each row
 
872
                                        * is usually connected to knowing
 
873
                                        * the indices of nonzero entries,
 
874
                                        * which the sparsity pattern is
 
875
                                        * designed to describe.
 
876
                                        */
 
877
      void
 
878
      reinit (const IndexSet                  &parallel_partitioning,
 
879
              const MPI_Comm                  &communicator,
 
880
              const std::vector<unsigned int> &n_entries_per_row);
 
881
 
 
882
                                       /**
 
883
                                        * This reinit function is similar to
 
884
                                        * the one above, but it now takes
 
885
                                        * two different index sets for rows
 
886
                                        * and columns. This interface is
 
887
                                        * meant to be used for generating
 
888
                                        * rectangular sparsity pattern,
 
889
                                        * where one index set describes the
 
890
                                        * %parallel partitioning of the dofs
 
891
                                        * associated with the sparsity
 
892
                                        * pattern rows and the other one of
 
893
                                        * the sparsity pattern columns. Note
 
894
                                        * that there is no real parallelism
 
895
                                        * along the columns &ndash; the
 
896
                                        * processor that owns a certain row
 
897
                                        * always owns all the column
 
898
                                        * elements, no matter how far they
 
899
                                        * might be spread out. The second
 
900
                                        * IndexSet is only used to specify
 
901
                                        * the number of columns and for
 
902
                                        * internal arragements when doing
 
903
                                        * matrix-vector products with
 
904
                                        * vectors based on an EpetraMap
 
905
                                        * based on that IndexSet.
 
906
                                        *
 
907
                                        * The number of columns entries per
 
908
                                        * row is specified by the argument
 
909
                                        * <tt>n_entries_per_row</tt>.
 
910
                                        */
 
911
      void
 
912
      reinit (const IndexSet     &row_parallel_partitioning,
 
913
              const IndexSet     &col_parallel_partitioning,
 
914
              const MPI_Comm     &communicator = MPI_COMM_WORLD,
 
915
              const unsigned int  n_entries_per_row = 0);
 
916
 
 
917
                                       /**
 
918
                                        * Same as before, but now using a
 
919
                                        * vector <tt>n_entries_per_row</tt>
 
920
                                        * for specifying the number of
 
921
                                        * entries in each row of the
 
922
                                        * sparsity pattern.
 
923
                                        */
 
924
      void
 
925
      reinit (const IndexSet                  &row_parallel_partitioning,
 
926
              const IndexSet                  &col_parallel_partitioning,
 
927
              const MPI_Comm                  &communicator,
 
928
              const std::vector<unsigned int> &n_entries_per_row);
 
929
 
 
930
                                       /**
 
931
                                        * Reinit function. Takes one of the
 
932
                                        * deal.II sparsity patterns and the
 
933
                                        * %parallel partitioning of the rows
 
934
                                        * and columns specified by two index
 
935
                                        * sets and a %parallel communicator
 
936
                                        * for initializing the current
 
937
                                        * Trilinos sparsity pattern. The
 
938
                                        * optional argument @p exchange_data
 
939
                                        * can be used for reinitialization
 
940
                                        * with a sparsity pattern that is
 
941
                                        * not fully constructed. This
 
942
                                        * feature is only implemented for
 
943
                                        * input sparsity patterns of type
 
944
                                        * CompressedSimpleSparsityPattern.
 
945
                                        */
 
946
      template<typename SparsityType>
 
947
      void
 
948
      reinit (const IndexSet     &row_parallel_partitioning,
 
949
              const IndexSet     &col_parallel_partitioning,
 
950
              const SparsityType &nontrilinos_sparsity_pattern,
 
951
              const MPI_Comm     &communicator = MPI_COMM_WORLD,
 
952
              const bool          exchange_data = false);
 
953
 
 
954
                                       /**
 
955
                                        * Reinit function. Takes one of the
 
956
                                        * deal.II sparsity patterns and a
 
957
                                        * %parallel partitioning of the rows
 
958
                                        * and columns for initializing the
 
959
                                        * current Trilinos sparsity
 
960
                                        * pattern. The optional argument @p
 
961
                                        * exchange_data can be used for
 
962
                                        * reinitialization with a sparsity
 
963
                                        * pattern that is not fully
 
964
                                        * constructed. This feature is only
 
965
                                        * implemented for input sparsity
 
966
                                        * patterns of type
 
967
                                        * CompressedSimpleSparsityPattern.
 
968
                                        */
 
969
      template<typename SparsityType>
 
970
      void
 
971
      reinit (const IndexSet     &parallel_partitioning,
 
972
              const SparsityType &nontrilinos_sparsity_pattern,
 
973
              const MPI_Comm     &communicator = MPI_COMM_WORLD,
 
974
              const bool          exchange_data = false);
 
975
//@}
 
976
/**
672
977
 * @name Information on the sparsity pattern
673
978
 */
674
979
//@{
688
993
                                        * processor.
689
994
                                        */
690
995
      unsigned int max_entries_per_row () const;
691
 
      
 
996
 
692
997
                                       /**
693
998
                                        * Return the number of rows in this
694
999
                                        * sparsity pattern.
869
1174
                                        * matrix.
870
1175
                                        */
871
1176
      const Epetra_Map & col_partitioner () const;
 
1177
 
 
1178
                                       /**
 
1179
                                        * Return a const reference to
 
1180
                                        * the communicator used for
 
1181
                                        * this object.
 
1182
                                        */
 
1183
      const Epetra_Comm & trilinos_communicator () const;
872
1184
//@}
873
1185
/**
874
1186
 * @name Iterators
936
1248
      void write_ascii ();
937
1249
 
938
1250
                                       /**
939
 
                                        * Print the sparsity pattern to the
940
 
                                        * given stream, using the format
941
 
                                        * <tt>(line,col)</tt>.
 
1251
                                        * Print (the locally owned part of)
 
1252
                                        * the sparsity pattern to the given
 
1253
                                        * stream, using the format
 
1254
                                        * <tt>(line,col)</tt>. The optional
 
1255
                                        * flag outputs the sparsity pattern
 
1256
                                        * in Trilinos style, where even the
 
1257
                                        * according processor number is
 
1258
                                        * printed to the stream, as well as
 
1259
                                        * a summary before actually writing
 
1260
                                        * the entries.
942
1261
                                        */
943
 
      void print (std::ostream &out) const;
 
1262
      void print (std::ostream &out,
 
1263
                  const bool    write_extended_trilinos_info = false) const;
944
1264
 
945
1265
                                       /**
946
1266
                                        * Print the sparsity of the matrix
968
1288
                                        * <tt>plot</tt> command.
969
1289
                                        */
970
1290
      void print_gnuplot (std::ostream &out) const;
971
 
    
972
 
                                        // TODO: Write an overloading
973
 
                                        // of the operator << for output.
974
 
                                        // Since the underlying Trilinos 
975
 
                                        // object supports it, this should 
976
 
                                        // be very easy.
977
1291
 
978
1292
//@}
979
1293
                                     /** @addtogroup Exceptions
1019
1333
                      << "/" << arg2 << ")"
1020
1334
                      << " of a sparse matrix, but it appears to not"
1021
1335
                      << " exist in the Trilinos sparsity pattern.");
1022
 
                                     //@}    
 
1336
                                     //@}
1023
1337
    private:
1024
 
                                       /**
1025
 
                                        * Epetra Trilinos
1026
 
                                        * mapping of the matrix rows
1027
 
                                        * that assigns parts of the
1028
 
                                        * matrix to the individual
1029
 
                                        * processes. This map is
1030
 
                                        * provided either via the
1031
 
                                        * constructor or in a reinit
1032
 
                                        * function.
1033
 
                                        */
1034
 
      Epetra_Map row_map;
1035
1338
 
1036
1339
                                       /**
1037
1340
                                        * Pointer to the user-supplied
1040
1343
                                        * assigns parts of the matrix
1041
1344
                                        * to the individual processes.
1042
1345
                                        */
1043
 
      Epetra_Map col_map;
 
1346
      std_cxx1x::shared_ptr<Epetra_Map> column_space_map;
1044
1347
 
1045
1348
                                       /**
1046
1349
                                        * A boolean variable to hold
1056
1359
                                        * allows for adding non-local
1057
1360
                                        * elements to the pattern.
1058
1361
                                        */
1059
 
      std::auto_ptr<Epetra_FECrsGraph> graph;
 
1362
      std_cxx1x::shared_ptr<Epetra_FECrsGraph> graph;
1060
1363
 
1061
1364
      friend class SparsityPatternIterators::const_iterator;
1062
1365
      friend class SparsityPatternIterators::const_iterator::Accessor;
1131
1434
    const_iterator &
1132
1435
    const_iterator::operator++ ()
1133
1436
    {
1134
 
      Assert (accessor.a_row < accessor.sparsity_pattern->n_rows(), 
 
1437
      Assert (accessor.a_row < accessor.sparsity_pattern->n_rows(),
1135
1438
              ExcIteratorPastEnd());
1136
1439
 
1137
1440
      ++accessor.a_index;
1138
1441
 
1139
1442
                                        // If at end of line: do one
1140
 
                                        // step, then cycle until we 
 
1443
                                        // step, then cycle until we
1141
1444
                                        // find a row with a nonzero
1142
1445
                                        // number of entries.
1143
1446
      if (accessor.a_index >= accessor.colnum_cache->size())
1144
1447
        {
1145
1448
          accessor.a_index = 0;
1146
1449
          ++accessor.a_row;
1147
 
      
 
1450
 
1148
1451
          while ((accessor.a_row < accessor.sparsity_pattern->n_rows())
1149
1452
                 &&
1150
1453
                 (accessor.sparsity_pattern->row_length(accessor.a_row) == 0))
1216
1519
              (accessor.row() == other.accessor.row() &&
1217
1520
               accessor.index() < other.accessor.index()));
1218
1521
    }
1219
 
    
 
1522
 
1220
1523
  }
1221
 
 
 
1524
 
1222
1525
 
1223
1526
 
1224
1527
  inline
1264
1567
    for (unsigned int i=r+1; i<n_rows(); ++i)
1265
1568
      if (row_length(i) > 0)
1266
1569
        return const_iterator(this, i, 0);
1267
 
    
 
1570
 
1268
1571
                                     // if there is no such line, then take the
1269
1572
                                     // end iterator of the matrix
1270
1573
    return end();
1279
1582
    int begin, end;
1280
1583
    begin = graph->RowMap().MinMyGID();
1281
1584
    end = graph->RowMap().MaxMyGID()+1;
1282
 
    
 
1585
 
1283
1586
    return ((index >= static_cast<unsigned int>(begin)) &&
1284
1587
            (index < static_cast<unsigned int>(end)));
1285
1588
  }
1329
1632
    const int n_cols = static_cast<int>(end - begin);
1330
1633
    compressed = false;
1331
1634
 
1332
 
    const int ierr = graph->InsertGlobalIndices (1, (int*)&row, 
 
1635
    const int ierr = graph->InsertGlobalIndices (1, (int*)&row,
1333
1636
                                                 n_cols, col_index_ptr);
1334
1637
 
1335
1638
    AssertThrow (ierr >= 0, ExcTrilinosError(ierr));
1381
1684
  }
1382
1685
 
1383
1686
 
1384
 
#endif // DOXYGEN      
 
1687
 
 
1688
  inline
 
1689
  const Epetra_Comm &
 
1690
  SparsityPattern::trilinos_communicator () const
 
1691
  {
 
1692
    return graph->RangeMap().Comm();
 
1693
  }
 
1694
 
 
1695
 
 
1696
 
 
1697
  inline
 
1698
  SparsityPattern::SparsityPattern  (const IndexSet     &parallel_partitioning,
 
1699
                                     const MPI_Comm     &communicator,
 
1700
                                     const unsigned int  n_entries_per_row)
 
1701
                  :
 
1702
                  compressed (false)
 
1703
  {
 
1704
    Epetra_Map map = parallel_partitioning.make_trilinos_map (communicator,
 
1705
                                                              false);
 
1706
    reinit (map, map, n_entries_per_row);
 
1707
  }
 
1708
 
 
1709
 
 
1710
 
 
1711
  inline
 
1712
  SparsityPattern::SparsityPattern  (const IndexSet     &parallel_partitioning,
 
1713
                                     const MPI_Comm     &communicator,
 
1714
                                     const std::vector<unsigned int> &n_entries_per_row)
 
1715
                  :
 
1716
                  compressed (false)
 
1717
  {
 
1718
    Epetra_Map map = parallel_partitioning.make_trilinos_map (communicator,
 
1719
                                                              false);
 
1720
    reinit (map, map, n_entries_per_row);
 
1721
  }
 
1722
 
 
1723
 
 
1724
 
 
1725
  inline
 
1726
  SparsityPattern::SparsityPattern  (const IndexSet     &row_parallel_partitioning,
 
1727
                                     const IndexSet     &col_parallel_partitioning,
 
1728
                                     const MPI_Comm     &communicator,
 
1729
                                     const unsigned int  n_entries_per_row)
 
1730
                  :
 
1731
                  compressed (false)
 
1732
  {
 
1733
    Epetra_Map row_map =
 
1734
      row_parallel_partitioning.make_trilinos_map (communicator, false);
 
1735
    Epetra_Map col_map =
 
1736
      col_parallel_partitioning.make_trilinos_map (communicator, false);
 
1737
    reinit (row_map, col_map, n_entries_per_row);
 
1738
  }
 
1739
 
 
1740
 
 
1741
 
 
1742
  inline
 
1743
  SparsityPattern::
 
1744
  SparsityPattern  (const IndexSet     &row_parallel_partitioning,
 
1745
                    const IndexSet     &col_parallel_partitioning,
 
1746
                    const MPI_Comm     &communicator,
 
1747
                    const std::vector<unsigned int> &n_entries_per_row)
 
1748
                  :
 
1749
                  compressed (false)
 
1750
  {
 
1751
    Epetra_Map row_map =
 
1752
      row_parallel_partitioning.make_trilinos_map (communicator, false);
 
1753
    Epetra_Map col_map =
 
1754
      col_parallel_partitioning.make_trilinos_map (communicator, false);
 
1755
    reinit (row_map, col_map, n_entries_per_row);
 
1756
  }
 
1757
 
 
1758
 
 
1759
 
 
1760
  inline
 
1761
  void
 
1762
  SparsityPattern::reinit (const IndexSet     &parallel_partitioning,
 
1763
                           const MPI_Comm     &communicator,
 
1764
                           const unsigned int  n_entries_per_row)
 
1765
  {
 
1766
    Epetra_Map map = parallel_partitioning.make_trilinos_map (communicator,
 
1767
                                                              false);
 
1768
    reinit (map, map, n_entries_per_row);
 
1769
  }
 
1770
 
 
1771
 
 
1772
 
 
1773
  inline
 
1774
  void SparsityPattern::reinit (const IndexSet     &parallel_partitioning,
 
1775
                                const MPI_Comm     &communicator,
 
1776
                                const std::vector<unsigned int> &n_entries_per_row)
 
1777
  {
 
1778
    Epetra_Map map = parallel_partitioning.make_trilinos_map (communicator,
 
1779
                                                              false);
 
1780
    reinit (map, map, n_entries_per_row);
 
1781
  }
 
1782
 
 
1783
 
 
1784
 
 
1785
  inline
 
1786
  void SparsityPattern::reinit (const IndexSet     &row_parallel_partitioning,
 
1787
                                const IndexSet     &col_parallel_partitioning,
 
1788
                                const MPI_Comm     &communicator,
 
1789
                                const unsigned int  n_entries_per_row)
 
1790
  {
 
1791
    Epetra_Map row_map =
 
1792
      row_parallel_partitioning.make_trilinos_map (communicator, false);
 
1793
    Epetra_Map col_map =
 
1794
      col_parallel_partitioning.make_trilinos_map (communicator, false);
 
1795
    reinit (row_map, col_map, n_entries_per_row);
 
1796
  }
 
1797
 
 
1798
 
 
1799
  inline
 
1800
  void
 
1801
  SparsityPattern::reinit (const IndexSet     &row_parallel_partitioning,
 
1802
                           const IndexSet     &col_parallel_partitioning,
 
1803
                           const MPI_Comm     &communicator,
 
1804
                           const std::vector<unsigned int> &n_entries_per_row)
 
1805
  {
 
1806
    Epetra_Map row_map =
 
1807
      row_parallel_partitioning.make_trilinos_map (communicator, false);
 
1808
    Epetra_Map col_map =
 
1809
      col_parallel_partitioning.make_trilinos_map (communicator, false);
 
1810
    reinit (row_map, col_map, n_entries_per_row);
 
1811
  }
 
1812
 
 
1813
 
 
1814
 
 
1815
  template<typename SparsityType>
 
1816
  inline
 
1817
  void
 
1818
  SparsityPattern::reinit (const IndexSet     &row_parallel_partitioning,
 
1819
                           const IndexSet     &col_parallel_partitioning,
 
1820
                           const SparsityType &nontrilinos_sparsity_pattern,
 
1821
                           const MPI_Comm     &communicator,
 
1822
                           const bool          exchange_data)
 
1823
  {
 
1824
    Epetra_Map row_map =
 
1825
      row_parallel_partitioning.make_trilinos_map (communicator, false);
 
1826
    Epetra_Map col_map =
 
1827
      col_parallel_partitioning.make_trilinos_map (communicator, false);
 
1828
    reinit (row_map, col_map, nontrilinos_sparsity_pattern, exchange_data);
 
1829
  }
 
1830
 
 
1831
 
 
1832
 
 
1833
  template<typename SparsityType>
 
1834
  inline
 
1835
  void
 
1836
  SparsityPattern::reinit (const IndexSet     &parallel_partitioning,
 
1837
                           const SparsityType &nontrilinos_sparsity_pattern,
 
1838
                           const MPI_Comm     &communicator,
 
1839
                           const bool          exchange_data)
 
1840
  {
 
1841
    Epetra_Map map = parallel_partitioning.make_trilinos_map (communicator,
 
1842
                                                              false);
 
1843
    reinit (map, map, nontrilinos_sparsity_pattern, exchange_data);
 
1844
  }
 
1845
 
 
1846
#endif // DOXYGEN
1385
1847
}
1386
1848
 
1387
1849