/[escript]/branches/doubleplusgood/paso/src/SparseMatrix_invMain.cpp
ViewVC logotype

Annotation of /branches/doubleplusgood/paso/src/SparseMatrix_invMain.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3911 - (hide 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 gross 3094
2     /*******************************************************
3     *
4 jfenwick 3911 * Copyright (c) 2003-2012 by University of Queensland
5 gross 3094 * 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 gross 3120 #include "BlockOps.h"
30 gross 3158 #include "PasoUtil.h"
31 gross 3094
32     void Paso_SparseMatrix_invMain(Paso_SparseMatrix * A_p, double* inv_diag, int* pivot) {
33 gross 3402 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 gross 3094 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 jfenwick 3259 Esys_setError(TYPE_ERROR, "Paso_SparseMatrix_invMain: square block size expected.");
45 gross 3094 }
46 jfenwick 3259 if (Esys_noError()) {
47 gross 3094
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 gross 3402 failed=1;
57 gross 3094 }
58     }
59     } else if (n_block==2) {
60 gross 3402 #pragma omp parallel for private(i, iPtr) schedule(static)
61 gross 3094 for (i = 0; i < n; i++) {
62     iPtr= main_ptr[i];
63 gross 3402 Paso_BlockOps_invM_2(&inv_diag[i*4], &A_p->val[iPtr*4], &failed);
64 gross 3094 }
65     } else if (n_block==3) {
66 gross 3402 #pragma omp parallel for private(i, iPtr) schedule(static)
67 gross 3094 for (i = 0; i < n; i++) {
68     iPtr= main_ptr[i];
69 gross 3402 Paso_BlockOps_invM_3(&inv_diag[i*9], &A_p->val[iPtr*9], &failed);
70 gross 3094 }
71 gross 3402 } else {
72     #pragma omp parallel for private(i, iPtr) schedule(static)
73 gross 3094 for (i = 0; i < n; i++) {
74     iPtr= main_ptr[i];
75 gross 3402 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 gross 3094 }
79     }
80 gross 3402 if (failed > 0) {
81     Esys_setError(ZERO_DIVISION_ERROR, "Paso_SparseMatrix_invMain: non-regular main diagonal block.");
82     }
83 gross 3094 }
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 gross 3158 Paso_Copy(n_block*n, x,b);
91 gross 3402 Paso_BlockOps_solveAll(n_block,n,block_diag,pivot,x);
92 gross 3094 }
93    

  ViewVC Help
Powered by ViewVC 1.1.26