Logo  0.95.0-final
Finite Element Embedded Library and Language in C++
Feel++ Feel++ on Github Feel++ community
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
graphcsr.hpp
Go to the documentation of this file.
1 /* -*- mode: c++; coding: utf-8; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; show-trailing-whitespace: t -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
2 
3  This file is part of the Feel library
4 
5  Author(s): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
6  Date: 2007-10-29
7 
8  Copyright (C) 2007-2011 Universite Joseph Fourier (Grenoble I)
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Lesser General Public
12  License as published by the Free Software Foundation; either
13  version 3.0 of the License, or (at your option) any later version.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public
21  License along with this library; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
30 #ifndef __GraphCSR_H
31 #define __GraphCSR_H 1
32 
33 #include <vector>
34 #include <map>
35 #include <set>
36 #include <boost/tuple/tuple.hpp>
37 //#include <boost/mpi/communicator.hpp>
38 
39 #include <boost/shared_ptr.hpp>
40 
41 #include <feel/feelcore/feel.hpp>
43 #include <feel/feelalg/datamap.hpp>
44 #include <feel/feelvf/block.hpp>
45 
46 namespace Feel
47 {
48 namespace mpi=boost::mpi;
49 
57 class GraphCSR
58 {
59 public:
60 
61 
65 
66  typedef GraphCSR self_type;
67  typedef boost::shared_ptr<self_type> self_ptrtype;
68 
69  typedef std::vector<size_type> nz_type;
70  typedef boost::shared_ptr<nz_type> nz_ptrtype;
71 
72  //typedef boost::tuple<size_type, size_type, std::vector<size_type> > row_type;
73  typedef boost::tuple<size_type, size_type, std::set<size_type> > row_type;
74  typedef std::map<size_type, row_type > storage_type;
75  typedef boost::shared_ptr<storage_type> storage_ptrtype;
76 
77  typedef storage_type::iterator iterator;
78  typedef storage_type::const_iterator const_iterator;
80 
84 
89  GraphCSR( size_type n = 0,
90  size_type first_row_entry_on_proc = 0,
91  size_type last_row_entry_on_proc = 0,
92  size_type first_col_entry_on_proc = 0,
93  size_type last_col_entry_on_proc = 0,
94  WorldComm const& worldcomm = Environment::worldComm() );
95 
96  GraphCSR( boost::shared_ptr<DataMap> const& mapRow,
97  boost::shared_ptr<DataMap> const& mapCol );
98 
99  GraphCSR( DataMap const& mapRow,
100  DataMap const& mapCol );
101 
102  GraphCSR( vf::BlocksBase<self_ptrtype> const & blockSet,
103  bool diagIsNonZero=true,
104  bool close=true );
105 
109  GraphCSR( GraphCSR const & g );
110 
114  ~GraphCSR();
115 
117 
121 
123  GraphCSR& operator=( GraphCSR const& g );
124 
126 
130 
131  size_type nRows() const
132  {
133  return M_last_row_entry_on_proc[this->worldComm().globalRank()]+1;
134  }
135  size_type nCols() const
136  {
137  return M_last_col_entry_on_proc[this->worldComm().globalRank()]+1;
138  }
139 
144  {
145  return M_first_row_entry_on_proc[this->worldComm().globalRank()];
146  }
147 
152  {
153  return M_last_row_entry_on_proc[this->worldComm().globalRank()];
154  }
159  {
160  return M_first_col_entry_on_proc[this->worldComm().globalRank()];
161  }
162 
167  {
168  return M_last_col_entry_on_proc[this->worldComm().globalRank()];
169  }
170 
174  size_type size() const
175  {
176  return M_storage.size();
177  }
181  bool empty() const
182  {
183  return M_storage.empty();
184  }
188  iterator begin()
189  {
190  return M_storage.begin();
191  }
192 
196  iterator end()
197  {
198  return M_storage.end();
199  }
200 
204  const_iterator begin() const
205  {
206  return M_storage.begin();
207  }
211  const_iterator end() const
212  {
213  return M_storage.end();
214  }
218  row_type& row( size_type i )
219  {
220  return M_storage[i];
221  }
222 
226  row_type const& row( size_type i ) const
227  {
228  return M_storage.find( i )->second;
229  }
230 
234  storage_type const& storage() const
235  {
236  return M_storage;
237  }
238 
239 
244  {
245  return M_max_nnz;
246  }
247 
253  std::vector<size_type> const&
254  nNz() const
255  {
256  return M_n_total_nz;
257  }
258 
263  std::vector<size_type> const&
264  nNzOnProc() const
265  {
266  return M_n_nz;
267  }
268 
273  std::vector<size_type> const&
274  nNzOffProc() const
275  {
276  return M_n_oz;
277  }
278 
282  //mpi::communicator const& comm() const { return M_comm; }
283  WorldComm const& worldComm() const
284  {
285  return M_worldComm;
286  }
287 
288  nz_type const& ia() const
289  {
290  return M_ia;
291  }
292  nz_type const& ja() const
293  {
294  return M_ja;
295  }
296  std::vector<double> const& a() const
297  {
298  return M_a;
299  }
300  std::vector<double>& a()
301  {
302  return M_a;
303  }
304 
305 
307 
311 
312 
313  void setFirstRowEntryOnProc( size_type entry )
314  {
315  M_first_row_entry_on_proc[this->worldComm().globalRank()] = entry;
316  }
317  void setFirstColEntryOnProc( size_type entry )
318  {
319  M_first_col_entry_on_proc[this->worldComm().globalRank()] = entry;
320  }
321 
322  void setLastRowEntryOnProc( size_type entry )
323  {
324  M_last_row_entry_on_proc[this->worldComm().globalRank()] = entry;
325  }
326  void setLastColEntryOnProc( size_type entry )
327  {
328  M_last_col_entry_on_proc[this->worldComm().globalRank()] = entry;
329  }
330 
331  DataMap const& mapRow() const { return *M_mapRow; }
332  DataMap const& mapCol() const { return *M_mapCol; }
333  boost::shared_ptr<DataMap> const& mapRowPtr() const { return M_mapRow; }
334  boost::shared_ptr<DataMap> const& mapColPtr() const { return M_mapCol; }
335  boost::shared_ptr<DataMap> mapRowPtr() { return M_mapRow; }
336  boost::shared_ptr<DataMap> mapColPtr() { return M_mapCol; }
337 
339 
343 
347  void zero();
348 
353  void close();
354 
358  self_ptrtype transpose( bool doClose = true );
359 
364 
368  void showMe( std::ostream& __out = std::cout ) const;
369 
370  void printPython( std::string const& nameFile ) const;
371 
373 
374 private :
375 
376  void mergeBlockGraph( self_ptrtype const& g,
377  size_type start_i, size_type start_j );
378 
379  void mergeBlockGraphMPI( self_ptrtype const& g, vf::BlocksBase<self_ptrtype> const & blockSet, int i, int j,
380  size_type start_i, size_type start_j );
381 
382  void updateDataMap( vf::BlocksBase<self_ptrtype> const & blockSet );
383 
384  size_type nLocalDofWithoutGhostOnProcStartRow( vf::BlocksBase<self_ptrtype> const & blockSet, int proc, int rowIndex, int colIndex ) const;
385  size_type nLocalDofWithoutGhostOnProcStartCol( vf::BlocksBase<self_ptrtype> const & blockSet, int proc, int rowIndex, int colIndex ) const;
386  size_type nLocalDofWithGhostOnProcStartRow( vf::BlocksBase<self_ptrtype> const & blockSet, int proc, int rowIndex, int colIndex ) const;
387  size_type nLocalDofWithGhostOnProcStartCol( vf::BlocksBase<self_ptrtype> const & blockSet, int proc, int rowIndex, int colIndex ) const;
388 
389 protected:
390 
391 private:
392  bool M_is_closed;
393  //mpi::communicator M_comm;
394  WorldComm M_worldComm;
395 
396  std::vector<size_type> M_first_row_entry_on_proc;
397  std::vector<size_type> M_last_row_entry_on_proc;
398  std::vector<size_type> M_first_col_entry_on_proc;
399  std::vector<size_type> M_last_col_entry_on_proc;
400  size_type M_max_nnz;
401  nz_type M_n_total_nz;
402  nz_type M_n_nz;
403  nz_type M_n_oz;
404  storage_type M_storage;
405  nz_type M_ia, M_ja;
406  std::vector<double> M_a;
407 
408  self_ptrtype M_graphT;
409 
410  boost::shared_ptr<DataMap> M_mapRow, M_mapCol;
411 };
412 
413 
414 class BlocksBaseGraphCSR : public vf::BlocksBase<boost::shared_ptr<GraphCSR> >
415 {
416 public :
417  typedef vf::BlocksBase<boost::shared_ptr<GraphCSR> > super_type;
418  typedef BlocksBaseGraphCSR self_type;
419  typedef boost::shared_ptr<GraphCSR> graph_ptrtype;
420 
421  BlocksBaseGraphCSR(uint16_type nr,uint16_type nc)
422  :
423  super_type(nr,nc)
424  {}
425 
426  BlocksBaseGraphCSR(super_type const & b)
427  :
428  super_type(b)
429  {}
430 
431  self_type
432  operator<<( graph_ptrtype const& g ) const
433  {
434  return super_type::operator<<( g );
435  }
436 
437 };
438 
439 
440 
441 } // Feel
442 #endif /* __GraphCSR_H */

Generated on Fri Oct 25 2013 14:24:15 for Feel++ by doxygen 1.8.4