5 #ifndef FML_PAR_PARMAT_H 6 #define FML_PAR_PARMAT_H 15 #include "../_internals/types.hh" 19 template <
class MAT,
class VEC,
typename REAL>
26 void print(uint8_t ndigits=4,
bool add_final_blank=
true);
31 void fill_val(
const REAL v);
32 void fill_linspace(
const REAL start,
const REAL stop);
34 void fill_diag(
const VEC &d);
42 void scale(
const REAL s);
49 len_global_t nrows()
const {
return m_global;};
50 len_local_t nrows_local()
const {
return data.nrows();};
51 len_local_t ncols()
const {
return data.ncols();};
52 comm get_comm()
const {
return r;};
53 MAT& data_obj()
const {
return data;};
54 MAT& data_obj() {
return data;};
58 len_global_t m_global;
61 void num_preceding_rows();
62 len_t get_local_dim();
67 template <
class MAT,
class VEC,
typename REAL>
73 m_global = (len_global_t) data.nrows();
80 template <
class MAT,
class VEC,
typename REAL>
83 len_t n = data.ncols();
86 int myrank = r.
rank();
88 data.print(ndigits,
false);
90 for (
int rank=1; rank<r.
size(); rank++)
94 len_t m = data.nrows();
97 REAL *d = data.data_ptr();
98 for (
int i=0; i<m; i++)
101 r.
send(n, pv.data_ptr(), 0);
104 else if (myrank == 0)
109 for (
int i=0; i<m; i++)
111 r.
recv(n, pv.data_ptr(), rank);
112 pv.print(ndigits,
false);
128 template <
class MAT,
class VEC,
typename REAL>
132 r.
printf(0,
" %" PRIu64
"x%d", m_global, data.ncols());
133 r.
printf(0,
" type=%s",
typeid(REAL).name());
139 template <
class MAT,
class VEC,
typename REAL>
147 template <
class MAT,
class VEC,
typename REAL>
155 template <
class MAT,
class VEC,
typename REAL>
163 template <
class MAT,
class VEC,
typename REAL>
171 template <
class MAT,
class VEC,
typename REAL>
179 template <
class MAT,
class VEC,
typename REAL>
182 int ret = (int) data.any_inf();
189 template <
class MAT,
class VEC,
typename REAL>
192 int ret = (int) data.any_nan();
203 template <
class MAT,
class VEC,
typename REAL>
206 int myrank = r.
rank();
207 int size = r.
size();;
210 len_t m_local = data.nrows();
212 for (
int rank=1; rank<size; rank++)
214 if (myrank == (rank - 1))
216 len_global_t nb4_send = nb4 + ((len_global_t) m_local);
217 r.
send(1, &nb4_send, rank);
219 else if (myrank == rank)
221 len_global_t nr_prev_rank;
222 r.
recv(1, &nr_prev_rank, rank-1);
231 template <
class MAT,
class VEC,
typename REAL>
234 len_t local = m_global / r.
size();
235 len_t rem = (len_t) (m_global - (len_global_t) local*r.
size());
236 if (r.
rank()+1 <= rem)
MPI communicator data and helpers.
Definition: comm.hh:24
void barrier() const
Execute a barrier.
Definition: comm.hh:341
void send(int n, const T *data, int dest, int tag=0) const
Point-to-point send. Should be matched by a corresponding 'recv' call.
Definition: comm.hh:289
void allreduce(int n, T *data, MPI_Op op=MPI_SUM) const
Sum reduce operation across all processes in the MPI communicator.
Definition: comm.hh:358
int rank() const
Calling process rank (0-based index) in the MPI communicator.
Definition: comm.hh:66
int size() const
Total number of ranks in the MPI communicator.
Definition: comm.hh:68
void printf(int rank, const char *fmt,...) const
Helper wrapper around the C standard I/O 'printf()' function. Conceptually similar to guarding a norm...
Definition: comm.hh:196
void recv(int n, T *data, int source, int tag=0) const
Point-to-point receive. Should be matched by a corresponding 'send' call.
Definition: comm.hh:318