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

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