/* Copyright 2016 The Science and Technology Facilities Council (STFC) * * Authors: Jonathan Hogg (STFC) * * Licence: BSD licence, see LICENCE file for details * */ #include "ldlt_tpp.hxx" #include #include #include #include #include #include "framework.hxx" #include "ssids/cpu/kernels/wrappers.hxx" #include "ssids/cpu/kernels/ldlt_tpp.hxx" using namespace spral::ssids::cpu; namespace { template void print_d(int n, T *d) { bool first = true; for(int i=0; i::infinity() && d[2*i+1]!=0.0) { // Second half of 2x2 pivot: don't print brackets std::cout << " "; } else if(first) { std::cout << "("; } else { std::cout << ") ("; } if(d[2*i] == std::numeric_limits::infinity() && d[2*i+1]!=0.0) std::cout << std::setw(8) << " "; else std::cout << std::setw(8) << d[2*i]; first = false; } std::cout << ")" << std::endl; first = true; for(int i=0; i::infinity() && d[2*i+1]!=0.0) { // Second half of 2x2 pivot: don't print brackets std::cout << " "; } else if(first) { std::cout << "("; } else { std::cout << ") ("; } if(d[2*i+1] == 0.0) std::cout << std::setw(8) << " "; else std::cout << std::setw(8) << d[2*i+1]; first = false; } std::cout << ")" << std::endl; } template void solve(int m, int n, const int *perm, const T *l, int ldl, const T *d, const T *b, T *x) { for(int i=0; i void make_singular(int n, int col1, int col2, T *a, int lda) { T *col = new T[n]; T a11 = a[col1*(lda+1)]; T a21 = (col1 < col2) ? a[col1*lda + col2] : a[col2*lda + col1]; T scal = a21 / a11; // Read col1 and double it for(int i=0; i col) a[col*lda+row] *= 1000; else a[row*lda+col] *= 1000; } } // Reorders a into supplied permuation such that row/col i of the new a // contains row/col perm[i] of the original a template void reorder(int n, const int *perm, T *a, int lda) { T *a2 = new T[n*n]; // Copy to a2 with permutation for(int j=0; j void do_update(int n, int k, T *a22, const T *a21, int lda, const T* d) { // Form A_21 D_11 T *ad21 = new T[n*k]; for(int j=0; j(OP_N, OP_T, n, n, k, -1.0, ad21, n, a21, lda, 1.0, a22, lda); // Free memory delete[] ad21; } /// Permutes rows of a as per perm such that row i becomes row (perm[i]-offset) template void permute_rows(int n, int k, const int *reord, int *perm, T *a, int lda) { // Copy a and perm without permutation T *a2 = new T[n*k]; for(int j=0; j n) { // Apply outer product update do_update(m-n, q1, &l[n*(lda+1)], &l[n], lda, d); // Second (m-n) x (m-n) matrix [but add delays if any] q2 = ldlt_tpp_factor(m-q1, m-q1, &perm[q1], &l[q1*(lda+1)], lda, &d[2*q1], work, m, action, u, small, q1, &l[q1], lda); } EXPECT_EQ(m, q1+q2) << "(test " << test << " seed " << seed << ")" << std::endl; EXPECT_LE(find_l_abs_max(m, l, lda), 1.0/u) << "(test " << test << " seed " << seed << ")" << std::endl; // Print out matrices if requested if(debug) { std::cout << "q1=" << q1 << " q2=" << q2 << std::endl; std::cout << "L:" << std::endl; print_mat("%10.2e", m, l, lda, perm); std::cout << "D:" << std::endl; print_d(m, d); } // Perform solve double *soln = new double[m]; solve(m, q1, perm, l, lda, d, b, soln); if(debug) { printf("soln = "); for(int i=0; i void print_mat (int n, int *perm, T *a, int lda) { for(int i=0; i