32#ifndef SPARSEMATMPI_HPP
33#define SPARSEMATMPI_HPP
35#if defined(SUANPAN_MPI) && defined(SUANPAN_MKL)
41template<sp_d T>
class SparseMatMPIPARDISO final :
public SparseMat<T> {
50 SparseMatMPIPARDISO(
const uword in_row,
const uword in_col,
const uword in_elem = 0)
56 unique_ptr<MetaMat<T>>
make_copy()
override {
return std::make_unique<SparseMatMPIPARDISO>(*
this); }
59template<sp_d T>
int SparseMatMPIPARDISO<T>::direct_solve(Mat<T>& X,
const Mat<T>& B) {
60 X.set_size(B.n_rows, B.n_cols);
64 const auto n =
static_cast<int>(B.n_rows);
65 const auto nrhs =
static_cast<int>(B.n_cols);
66 const auto nnz =
static_cast<int>(csr_mat.n_elem);
69 MPI_Comm_spawn(
"solver.pardiso", MPI_ARGV_NULL,
SUANPAN_NUM_NODES, MPI_INFO_NULL, 0, MPI_COMM_SELF, &worker, MPI_ERRCODES_IGNORE);
80 config[7] = std::is_same_v<T, double> ? 1 : -1;
81 const auto FLOAT_TYPE = std::is_same_v<T, double> ? MPI_DOUBLE : MPI_FLOAT;
84 MPI_Intercomm_merge(worker, 0, &remote);
85 MPI_Bcast(&config, 8, MPI_INT, 0, remote);
87 MPI_Request requests[5];
88 MPI_Isend(&iparm, 64, MPI_INT, 0, 0, worker, &requests[0]);
89 MPI_Isend(csr_mat.row_mem(), n + 1, MPI_INT, 0, 0, worker, &requests[1]);
90 MPI_Isend(csr_mat.col_mem(), nnz, MPI_INT, 0, 0, worker, &requests[2]);
91 MPI_Isend(csr_mat.val_mem(), nnz, FLOAT_TYPE, 0, 0, worker, &requests[3]);
92 MPI_Isend(B.memptr(),
static_cast<int>(B.n_elem), FLOAT_TYPE, 0, 0, worker, &requests[4]);
93 MPI_Waitall(5, requests, MPI_STATUSES_IGNORE);
96 MPI_Recv(&
error, 1, MPI_INT, 0, 0, worker, MPI_STATUS_IGNORE);
98 MPI_Recv(X.memptr(),
static_cast<int>(B.n_elem), FLOAT_TYPE, 0, 0, worker, MPI_STATUS_IGNORE);
A SparseMat class that holds matrices.
Definition: SparseMat.hpp:34
int direct_solve(Mat< T > &X, Mat< T > &&B) override
Definition: SparseMat.hpp:38
int SUANPAN_NUM_NODES
Definition: command.cpp:73
void error(const std::string_view file_name, const int line, const std::string_view format_str, const T &... args)
Definition: suanPan.h:234
constexpr auto SUANPAN_SUCCESS
Definition: suanPan.h:172
constexpr auto SUANPAN_FAIL
Definition: suanPan.h:173