25#include "rheolef/asr.h"
26#include "rheolef/csr.h"
27#include "rheolef/iorheo.h"
28#include "rheolef/mm_io.h"
35template<
class T,
class M,
class A>
41 ext_ia = a.ext_begin();
42 size_type first_dis_i = a.row_ownership().first_index();
43 size_type first_dis_j = a.col_ownership().first_index();
44 for (
size_type i = 0, n = a.nrow(); i < n; i++) {
46 size_type dis_j = first_dis_j + (*p).first;
47 const T& value = (*p).second;
48 semi_dis_entry (i, dis_j) += value;
53 size_type dis_j = a.jext2dis_j ((*p).first);
54 const T& value = (*p).second;
55 semi_dis_entry (i, dis_j) += value;
63template <
class T,
class M,
class A>
68 for (
typename base::const_iterator
70 last = base::end(); iter != last; ++iter) {
71 _nnz += (*iter).size();
74#ifdef _RHEOLEF_HAVE_MPI
76 _dis_nnz = mpi::all_reduce (comm(), _nnz, std::plus<size_type>());
83template <
class T,
class M,
class A>
87 std::ostream& os = ods.
os();
88 std::string name = iorheo::getbasename(ods.
os());
89 if (name ==
"") name =
"a";
90 os << std::setprecision (std::numeric_limits<T>::digits10)
91 << name <<
" = spalloc(" << nrow() <<
"," << ncol() <<
"," << nnz() <<
");" << std::endl;
92 if (_nnz == 0)
return ods;
94 for (
typename base::const_iterator
96 last = base::end(); iter != last; ++iter, ++i) {
98 for (
typename row_type::const_iterator
99 row_iter = row.begin(),
100 row_last = row.end(); row_iter != row_last; ++row_iter) {
101 os << name <<
"(" << first_dis_i+i+1 <<
","
102 << (*row_iter).first+1 <<
") = "
103 << (*row_iter).second <<
";" << std::endl;
108template <
class T,
class M,
class A>
112 std::ostream& os = ods.
os();
113 os << std::setprecision(std::numeric_limits<T>::digits10)
114 <<
"%%MatrixMarket matrix coordinate real general" << std::endl
115 << nrow() <<
" " << ncol() <<
" " << nnz() << std::endl;
116 if (_nnz == 0)
return ods;
118 for (
typename base::const_iterator
119 iter = base::begin(),
120 last = base::end(); iter != last; ++iter, ++i) {
122 for (
typename row_type::const_iterator
123 row_iter = row.begin(),
124 row_last = row.end(); row_iter != row_last; ++row_iter) {
125 os << first_dis_i+i+1 <<
" "
126 << (*row_iter).first+1 <<
" "
127 << (*row_iter).second << std::endl;
132template <
class T,
class M,
class A>
138 {
return put_seq_sparse_matlab (ods,first_dis_i); }
140 return put_seq_matrix_market (ods,first_dis_i);
142template <
class T,
class M,
class A>
149 distributor io_row_ownership (dis_nrow(), comm(), (my_proc == io_proc ? dis_nrow() : 0));
150 distributor io_col_ownership (dis_ncol(), comm(), (my_proc == io_proc ? dis_ncol() : 0));
151 asr<T> a (io_row_ownership, io_col_ownership);
152 size_type first_dis_i = row_ownership().first_index();
154 for (
typename base::const_iterator
155 iter = base::begin(),
156 last = base::end(); iter != last; ++iter, ++i) {
158 for (
typename row_type::const_iterator
159 row_iter = row.begin(),
160 row_last = row.end(); row_iter != row_last; ++row_iter) {
161 a.dis_entry (first_dis_i + i, (*row_iter).first) += (*row_iter).second;
164 a.dis_entry_assembly();
165 if (my_proc == io_proc) {
171template <
class T,
class M,
class A>
176 return put_seq (ods);
178 return put_mpi (ods);
181template <
class T,
class M,
class A>
194 ips >> dis_nrow >> dis_ncol >> dis_nnz;
195 communicator comm = ips.
comm();
198 resize (row_ownership, col_ownership);
201 std::istream& is = ips.
is();
205 is >> dis_i >> dis_j >> value;
207 dis_entry(dis_i,dis_j) += value;
211 dis_entry(dis_j,dis_i) += value;
213 dis_entry(dis_j,dis_i) += -value;
217 dis_entry_assembly();
223#define _RHEOLEF_instanciation(T,M,A) \
224template class asr<T,M,A>;
227#ifdef _RHEOLEF_HAVE_MPI
#define _RHEOLEF_instanciation(T, M, A)
see the Float page for the full documentation
odiststream & put_seq_sparse_matlab(odiststream &ops, size_type first_dis_i=0) const
idiststream & get(idiststream &ips)
pair_set< T, A > row_type
odiststream & put_mpi(odiststream &ops) const
odiststream & put(odiststream &ops) const
base::size_type size_type
void build_from_csr(const csr_rep< T, M > &)
odiststream & put_seq(odiststream &ops, size_type first_dis_i=0) const
odiststream & put_seq_matrix_market(odiststream &ops, size_type first_dis_i=0) const
see the csr page for the full documentation
see the distributor page for the full documentation
static const size_type decide
idiststream: see the diststream page for the full documentation
static size_type io_proc()
This routine returns the rank of a process that can perform i/o.
const communicator & comm() const
std::bitset< last > flag_type
static flag_type format_field
odiststream: see the diststream page for the full documentation
static size_type io_proc()
check_macro(expr1.have_homogeneous_space(Xh1), "dual(expr1,expr2); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),expr2)")
This file is part of Rheolef.
struct matrix_market read_matrix_market_header(idiststream &ips)
static const format_type general
static const format_type symmetric
static const format_type skew_symmetric
static const format_type hermitian