# Contents of /branches/doubleplusgood/paso/src/SparseMatrix_invMain.cpp

Revision 4257 - (show annotations)
Wed Feb 27 03:42:40 2013 UTC (6 years ago) by jfenwick
Original Path: branches/doubleplusgood/paso/src/SparseMatrix_invMain.c
File MIME type: text/plain
File size: 3225 byte(s)
```Some simple experiments for c++ Finley

```
 1 2 /***************************************************************************** 3 * 4 * Copyright (c) 2003-2013 by University of Queensland 5 * http://www.uq.edu.au 6 * 7 * Primary Business: Queensland, Australia 8 * Licensed under the Open Software License version 3.0 9 * http://www.opensource.org/licenses/osl-3.0.php 10 * 11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC) 12 * Development since 2012 by School of Earth Sciences 13 * 14 *****************************************************************************/ 15 16 17 /************************************************************************************/ 18 19 /* Paso: inverts the main diagonal of a SparseMatrix: */ 20 21 /************************************************************************************/ 22 23 /* Author: Lutz Gross, l.gross@uq.edu.au */ 24 25 /************************************************************************************/ 26 27 #include "Paso.h" 28 #include "SparseMatrix.h" 29 #include "Solver.h" 30 #include "BlockOps.h" 31 #include "PasoUtil.h" 32 33 void Paso_SparseMatrix_invMain(Paso_SparseMatrix * A_p, double* inv_diag, int* pivot) { 34 index_t failed=0; 35 register double A11; 36 const dim_t n=A_p->numRows; 37 const dim_t n_block=A_p->row_block_size; 38 const dim_t m_block=A_p->col_block_size; 39 const dim_t block_size=A_p->block_size; 40 dim_t i; 41 register index_t iPtr; 42 index_t* main_ptr=Paso_Pattern_borrowMainDiagonalPointer(A_p->pattern); 43 /* check matrix is square */ 44 if (m_block != n_block) { 45 Esys_setError(TYPE_ERROR, "Paso_SparseMatrix_invMain: square block size expected."); 46 } 47 if (Esys_noError()) { 48 49 if (n_block==1) { 50 #pragma omp parallel for private(i, iPtr, A11) schedule(static) 51 for (i = 0; i < n; i++) { 52 iPtr= main_ptr[i]; 53 A11=A_p->val[iPtr]; 54 if ( ABS(A11) > 0.) { 55 inv_diag[i]=1./A11; 56 } else { 57 failed=1; 58 } 59 } 60 } else if (n_block==2) { 61 #pragma omp parallel for private(i, iPtr) schedule(static) 62 for (i = 0; i < n; i++) { 63 iPtr= main_ptr[i]; 64 Paso_BlockOps_invM_2(&inv_diag[i*4], &A_p->val[iPtr*4], &failed); 65 } 66 } else if (n_block==3) { 67 #pragma omp parallel for private(i, iPtr) schedule(static) 68 for (i = 0; i < n; i++) { 69 iPtr= main_ptr[i]; 70 Paso_BlockOps_invM_3(&inv_diag[i*9], &A_p->val[iPtr*9], &failed); 71 } 72 } else { 73 #pragma omp parallel for private(i, iPtr) schedule(static) 74 for (i = 0; i < n; i++) { 75 iPtr= main_ptr[i]; 76 Paso_BlockOps_Cpy_N(block_size, &inv_diag[i*block_size], &A_p->val[iPtr*block_size]); 77 Paso_BlockOps_invM_N(n_block, &inv_diag[i*block_size], &pivot[i*n_block], &failed); 78 } 79 } 80 } 81 if (failed > 0) { 82 Esys_setError(ZERO_DIVISION_ERROR, "Paso_SparseMatrix_invMain: non-regular main diagonal block."); 83 } 84 } 85 void Paso_SparseMatrix_applyBlockMatrix(Paso_SparseMatrix * A_p, double* block_diag, int* pivot, double*x, double *b) { 86 87 /* inv_diag=MEMALLOC( A->numRows * A_p-> block_size,double); 88 pivot=MEMALLOC( A->numRows * A->row_block_size */ 89 dim_t n=A_p->numRows; 90 dim_t n_block=A_p->row_block_size; 91 Paso_Copy(n_block*n, x,b); 92 Paso_BlockOps_solveAll(n_block,n,block_diag,pivot,x); 93 } 94