19 #ifndef SELDON_FILE_PASTIX_CXX
30 comm_ = MPI_COMM_WORLD;
34 for (
int i = 0; i < IPARM_SIZE; i++)
37 for (
int i = 0; i < DPARM_SIZE; i++)
44 refine_solution =
false;
47 pastixInitParam(iparm, dparm);
48 spm = (spmatrix_t*)malloc(
sizeof(spmatrix_t));
50 iparm[IPARM_VERBOSE] = PastixVerboseNot;
51 iparm[IPARM_FREE_CSCUSER] = 1;
53 threshold_pivot = 0.0;
54 adjust_threshold_pivot =
false;
71 if (
sizeof(pastix_int_t) == 8)
84 pastixFinalize(&pastix_data);
97 iparm[IPARM_VERBOSE] = PastixVerboseNot;
105 iparm[IPARM_VERBOSE] = PastixVerboseNo;
113 iparm[IPARM_VERBOSE] = PastixVerboseYes;
121 iparm[IPARM_ORDERING] = type;
129 iparm[IPARM_ORDERING] = PastixOrderPersonal;
130 pastixOrderAlloc(&ord, permut.GetM(), 0);
131 for (
int i = 0; i < permut.GetM(); i++)
133 ord.permtab[i] = permut(i);
134 ord.peritab[permut(i)] = i;
151 adjust_threshold_pivot =
true;
152 threshold_pivot = eps;
160 refine_solution =
true;
168 refine_solution =
false;
181 taille += (
sizeof(T)+
sizeof(pastix_int_t))*iparm[IPARM_NNZEROS];
195 template<
class T0,
class Prop,
class Storage,
class Allocator,
class T
int>
211 GetSymmetricPattern(mat, Ptr, Ind);
215 cout <<
"Not implemented" << endl;
221 template<
class T>
template<
class T0,
class Storage,
class Allocator>
233 ConvertToCSC(mat, prop, Ptr, IndRow, Val,
true);
237 FactorizeCSC(Ptr, IndRow, Val,
false);
248 pastix_int_t nnz = IndRow.GetM();
249 spm->fmttype = SpmCSC;
251 if (glob_number.GetM() < n)
252 spm->loc2glob = NULL;
256 spm->loc2glob = glob_num.GetData();
257 spm->comm = comm_facto;
258 int nb_proc, rank_proc;
259 MPI_Comm_size(comm_facto, &nb_proc);
260 MPI_Comm_rank(comm_facto, &rank_proc);
261 spm->clustnum = rank_proc;
262 spm->clustnbr = nb_proc;
269 spm->layout = SpmColMajor;
272 spm->flttype = SpmDouble;
274 spm->flttype = SpmComplex64;
277 spm->mtxtype = SpmSymmetric;
279 spm->mtxtype = SpmGeneral;
281 spm->colptr = Ptr.GetData();
282 spm->rowptr = IndRow.GetData();
283 spm->values = (
double*)Val.GetData();
285 spmUpdateComputedFields( spm );
288 int rc = spmCheckAndCorrect( spm, &spm2 );
291 cout <<
"Error in the matrix" << endl;
295 Ptr.Nullify(); IndRow.Nullify(); Val.Nullify();
301 ::FactorizeCSC(Vector<pastix_int_t>& Ptr, Vector<pastix_int_t>& IndRow,
302 Vector<T>& Val,
bool sym)
309 Vector<int> glob_num;
310 FillSpmMatrix(Ptr, IndRow, Val, sym, glob_num, MPI_COMM_SELF);
315 iparm[IPARM_FACTORIZATION] = PastixFactLLT;
317 iparm[IPARM_FACTORIZATION] = PastixFactLDLT;
320 iparm[IPARM_FACTORIZATION] = PastixFactLU;
323 if (adjust_threshold_pivot)
324 dparm[DPARM_EPSILON_MAGN_CTRL] = threshold_pivot;
326 pastixInit(&pastix_data, MPI_COMM_SELF, iparm, dparm);
329 pastix_task_analyze(pastix_data, spm);
332 pastix_task_numfact(pastix_data, spm);
334 if (iparm[IPARM_VERBOSE] != PastixVerboseNot)
335 cout <<
"Factorization successful" << endl;
340 template<
class T>
template<
class T0,
class Storage,
class Allocator>
352 ConvertToCSR(mat, prop, Ptr, IndRow, Val);
354 FactorizeCSC(Ptr, IndRow, Val,
true);
359 template<
class T>
template<
class Allocator2>
362 Solve(SeldonNoTrans, x);
367 template<
class T>
template<
class Allocator2>
371 Solve(TransA, x.GetData(), 1);
379 pastix_int_t nrhs = nrhs_;
383 spm_coeftype_t flttype;
387 flttype = SpmComplex64;
389 if (TransA.NoTrans())
391 pastix_subtask_applyorder(pastix_data, flttype, PastixDirForward,
392 n, nrhs, (
void*)x_ptr, n);
394 pastix_subtask_trsm(pastix_data, flttype, PastixLeft, PastixLower,
395 PastixNoTrans, PastixNonUnit, nrhs, (
void*)x_ptr, n);
399 pastix_subtask_trsm(pastix_data, flttype, PastixLeft, PastixLower,
400 PastixTrans, PastixNonUnit, nrhs, (
void*)x_ptr, n);
402 pastix_subtask_applyorder(pastix_data, flttype, PastixDirBackward,
403 n, nrhs, (
void*)x_ptr, n);
410 iparm[IPARM_TRANSPOSE_SOLVE] = PastixTrans;
412 iparm[IPARM_TRANSPOSE_SOLVE] = PastixNoTrans;
417 b_ptr = (T*) malloc(nrhs*n*
sizeof(T));
418 memcpy(b_ptr, x_ptr, nrhs*n*
sizeof(T));
421 pastix_task_solve(pastix_data, nrhs, (
void*)x_ptr, n);
423 pastix_task_refine(pastix_data, n, nrhs, (
void*)b_ptr, n, (
void*)x_ptr, n);
428 template<
class T>
template<
class Allocator2>
432 Solve(TransA, x.GetData(), x.GetN());
437 template<
class T>
template<
class Allocator2>
441 Mlt(TransA, x.GetData(), 1);
453 cout <<
"Multiplication with L Not implemented in MatrixPastix" << endl;
464 cout <<
"Mlt is defined for Cholesky only" << endl;
474 iparm[IPARM_THREAD_NBR] = num_thread;
483 bool sym,
bool keep_matrix)
486 for (
int i = 0; i < Ptr.GetM(); i++)
489 FactorizeParallel(comm_facto, PtrInt, IndRow, Val,
490 glob_number, sym, keep_matrix);
495 void MatrixPastix<T>::
496 FactorizeDistributedMatrix(MPI_Comm& comm_facto, Vector<int64_t>& Ptr,
497 Vector<int64_t>& IndRow, Vector<T>& Val,
498 const Vector<int>& glob_number,
499 bool sym,
bool keep_matrix)
501 FactorizeParallel(comm_facto, Ptr, IndRow, Val,
502 glob_number, sym, keep_matrix);
506 template<
class T>
template<
class T
int>
507 void MatrixPastix<T>::
508 FactorizeParallel(MPI_Comm& comm_facto,
509 Vector<Tint>&, Vector<Tint>&,
511 const Vector<int>& glob_num,
512 bool sym,
bool keep_matrix)
514 cout <<
"Not available for this type of integers " << endl;
515 cout <<
"Size of Tint = " <<
sizeof(Tint) << endl;
522 void MatrixPastix<T>::
523 FactorizeParallel(MPI_Comm& comm_facto,
527 bool sym,
bool keep_matrix)
531 iparm[IPARM_FREE_CSCUSER] = 0;
532 distributed =
true; n = Ptr.GetM()-1;
533 FillSpmMatrix(Ptr, IndRow, Val, sym, glob_number, comm_facto);
538 iparm[IPARM_FACTORIZATION] = PastixFactLLT;
540 iparm[IPARM_FACTORIZATION] = PastixFactLDLT;
543 iparm[IPARM_FACTORIZATION] = PastixFactLU;
546 if (adjust_threshold_pivot)
547 dparm[DPARM_EPSILON_MAGN_CTRL] = threshold_pivot;
549 pastixInit(&pastix_data, comm_facto, iparm, dparm);
552 pastix_task_analyze(pastix_data, spm);
555 pastix_task_numfact(pastix_data, spm);
560 template<
class T>
template<
class Allocator2>
566 SolveDistributed(comm_facto, TransA, x.GetData(), 1, glob_num);
575 const IVect& glob_num)
577 pastix_int_t nrhs = nrhs_;
581 cout <<
"Not implemented" << endl;
591 iparm[IPARM_TRANSPOSE_SOLVE] = PastixTrans;
593 iparm[IPARM_TRANSPOSE_SOLVE] = PastixNoTrans;
599 b_ptr = (T*) malloc(nrhs*n*
sizeof(T));
600 memcpy(b_ptr, x_ptr, nrhs*n*
sizeof(T));
603 pastix_task_solve(pastix_data, nrhs, (
void*)x_ptr, n);
605 pastix_task_refine(pastix_data, n, nrhs, (
void*)b_ptr, n, (
void*)x_ptr, n);
610 template<
class T>
template<
class Allocator2>
616 SolveDistributed(comm_facto, TransA, x.GetData(), x.GetN(), glob_num);
621 template<
class T>
template<
class Allocator2>
627 MltDistributed(comm_facto, TransA, x.GetData(), 1, glob_num);
636 const IVect& glob_num)
672 template<
class T>
template<
class Allocator2>
678 MltDistributed(comm_facto, TransA, x.GetData(), x.GetN(), glob_num);
683 template<
class MatrixSparse,
class T>
691 template<
class MatrixSparse,
class T>
694 throw WrongArgument(
"GetLU(Matrix<complex<T> >& A, MatrixPastix<T>& mat_lu, bool)",
695 "The LU matrix must be complex");
700 template<
class MatrixSparse,
class T>
703 throw WrongArgument(
"GetLU(Matrix<T>& A, MatrixMumps<Pastix<T> >& mat_lu, bool)",
704 "The sparse matrix must be complex");
709 template<
class T0,
class Prop,
class Storage,
class Allocator,
class T>
719 GetLU(A, mat_lu, keep_matrix, x);
724 template<
class T,
class Allocator>
733 template<
class T,
class Allocator>
737 mat_lu.
Solve(TransA, x);
742 template<
class T,
class Prop,
class Allocator>
746 mat_lu.
Solve(SeldonNoTrans, x);
752 template<
class T,
class Prop,
class Allocator>
756 mat_lu.
Solve(TransA, x);
761 template<
class Allocator>
767 for (
int i = 0; i < x.GetM(); i++)
769 y(i, 0) = real(x(i));
770 y(i, 1) = imag(x(i));
775 for (
int i = 0; i < x.GetM(); i++)
776 x(i) = complex<double>(y(i, 0), y(i, 1));
781 template<
class Allocator>
787 for (
int i = 0; i < x.GetM(); i++)
789 y(i, 0) = real(x(i));
790 y(i, 1) = imag(x(i));
793 SolveLU(TransA, mat_lu, y);
795 for (
int i = 0; i < x.GetM(); i++)
796 x(i) = complex<double>(y(i, 0), y(i, 1));
802 template<
class Allocator>
806 throw WrongArgument(
"SolveLU(MatrixPastix<complex<double> >, Vector<double>)",
807 "The result should be a complex vector");
812 template<
class Allocator>
817 throw WrongArgument(
"SolveLU(MatrixPastix<complex<double> >, Vector<double>)",
818 "The result should be a complex vector");
822 template<
class T,
class Prop,
class Storage,
class Allocator>
823 void GetCholesky(Matrix<T, Prop, Storage, Allocator>& A,
824 MatrixPastix<T>& mat_chol,
bool keep_matrix)
826 mat_chol.SetCholeskyFacto(
true);
829 mat_chol.FactorizeMatrix(A, keep_matrix);
833 template<
class T,
class Allocator>
835 SolveCholesky(
const SeldonTranspose& TransA,
836 MatrixPastix<T>& mat_chol, Vector<T, VectFull, Allocator>& x)
838 mat_chol.Solve(TransA, x);
842 template<
class T,
class Allocator>
844 MltCholesky(
const SeldonTranspose& TransA,
845 MatrixPastix<T>& mat_chol, Vector<T, VectFull, Allocator>& x)
847 mat_chol.Mlt(TransA, x);
852 #define SELDON_FILE_PASTIX_CXX