Subversion Repositories slepc-dev

Rev

Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2517 eromero 1
/*
2
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3
   SLEPc - Scalable Library for Eigenvalue Problem Computations
4
   Copyright (c) 2002-2010, Universidad Politecnica de Valencia, Spain
5
 
6
   This file is part of SLEPc.
7
 
8
   SLEPc is free software: you can redistribute it and/or modify it under  the
9
   terms of version 3 of the GNU Lesser General Public License as published by
10
   the Free Software Foundation.
11
 
12
   SLEPc  is  distributed in the hope that it will be useful, but WITHOUT  ANY
13
   WARRANTY;  without even the implied warranty of MERCHANTABILITY or  FITNESS
14
   FOR  A  PARTICULAR PURPOSE. See the GNU Lesser General Public  License  for
15
   more details.
16
 
17
   You  should have received a copy of the GNU Lesser General  Public  License
18
   along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
19
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20
*/
21
 
22
 
23
#ifndef __MATDENSE_H
24
#define __MATDENSE_H
25
 
26
#include <slepcmatdense.h>
27
 
28
typedef struct _MatDenseOps *MatDenseOps;
29
struct _MatDenseOps {
30
  /* 0*/
31
  PetscErrorCode (*getarray)(MatDense,PetscScalar**);
32
  PetscErrorCode (*restorearray)(MatDense,PetscScalar**);
2544 eromero 33
  PetscErrorCode (*getarrayread)(MatDense,const PetscScalar**);
34
  PetscErrorCode (*restorearrayread)(MatDense,const PetscScalar**);
2522 eromero 35
  PetscErrorCode (*duplicate)(MatDense,MatDenseDuplicateOption,MatDense*);
2517 eromero 36
  /* 5 */
2522 eromero 37
  PetscErrorCode (*axpy)(MatDense,PetscScalar,MatDense);
2517 eromero 38
  PetscErrorCode (*copy)(MatDense,MatDense);
2522 eromero 39
  PetscErrorCode (*setexplicit)(MatDense);
2517 eromero 40
  PetscErrorCode (*blas_axpy)(PetscInt,PetscScalar,MatDense,PetscInt,PetscInt,MatDense,PetscInt,PetscInt);
2522 eromero 41
  PetscErrorCode (*blas_copy)(PetscInt,MatDense,PetscInt,PetscInt,MatDense,PetscInt,PetscInt);
2517 eromero 42
  /* 10 */
2533 eromero 43
  PetscErrorCode (*destroy)(MatDense);
2517 eromero 44
  PetscErrorCode (*view)(MatDense,PetscViewer);
45
  PetscErrorCode (*setfromoptions)(MatDense);
46
  PetscErrorCode (*matmult)(MatDense,PetscScalar,PetscScalar,MatDense,PetscBool,MatDense,PetscBool);
2544 eromero 47
  PetscErrorCode (*matmult_blas)(MatDense,PetscScalar,PetscScalar,MatDense,PetscBool,MatDense,PetscBool);
48
  /* 15 */
2517 eromero 49
  PetscErrorCode (*setsizes)(MatDense,PetscInt,PetscInt,PetscInt,PetscInt);
50
  PetscErrorCode (*setuppreallocation)(MatDense);
2544 eromero 51
  PetscErrorCode (*aresiblings)(MatDense,MatDense,PetscBool*);
2852 eromero 52
  PetscErrorCode (*serialize)(MatDense,PetscInt*,PetscScalar*);
53
  PetscErrorCode (*deserialize)(MatDense,PetscInt,PetscScalar*);
2517 eromero 54
  PetscErrorCode (*create)(MatDense);  
55
};
56
 
57
struct _p_MatDense {
58
  PETSCHEADER(struct _MatDenseOps);
59
  void                   *data;            /* implementation-specific data */
60
  PetscInt               ld;               /* Lapack leading dimension of data */
61
  PetscInt               Mmax,Nmax;        /* indicates the largest dimensions of data possible */
62
  PetscInt               m0,n0,m,n;        /* indicates the current displacement and dimensions */
63
  PetscBool              is_allocated;     /* indicates where is the last valid copy of the data */
64
  PetscBool              is_hermitian,is_triangular,is_impl; /* indicates properties of the matrix and how it is stored */
2560 eromero 65
  PetscInt               matmult_buffersize;
66
                                           /* suggested size of the operator in bytes for storing the result in MatDenseMatMult_Siblings */
2852 eromero 67
  PetscBool              use_impl;         /* indicates if optimized functions for Hermitian or triangular matrix will be used  */
68
  PetscBool              use_mpi_queue;    /* indicates if the synchronous MPI operations are queued */
69
  PetscInt               n_getarray;       /* number of unrestored GetArray operations */
70
  PetscBool              is_pending;       /* indicates if a reduction is been performing */
2517 eromero 71
};
72
 
2522 eromero 73
/*MC
74
   PetscObjectQueryPolymorphicFunction1 - Returns in R the best function for the
75
   operation F, considering the type of A.
2517 eromero 76
 
2522 eromero 77
   Synopsis:
78
   PetscObjectQueryPolymorphicFunction(PetscObject A,field,const char *N,void *(*R)(void),PetscBool err)
79
 
80
   Not Collective
81
 
82
   Input Parameters:
83
+  A - PetscObject that participate in the operation
84
.  field - name of the field in structure ops that contains the function pointer
85
.  N - name of routine
86
-  err - if PETSC_TRUE, PetscError is called when any function is found
87
 
88
   Output Parameters:
89
.  R - the function pointer
90
 
91
   Level: development
92
 
93
M*/
94
#define PetscObjectQueryPolymorphicFunction1(A,F,N,R,E) { \
95
  if ((A)->ops->F) { \
96
    *(R) = (A)->ops->F; \
97
  } else {  \
98
    /* dispatch based on the type of A and B */ \
99
    char           name[256]; \
100
    PetscInt       i; \
101
    PetscErrorCode ierr; \
102
    for (i=0, *(R)=PETSC_NULL; !*(R) && i<2; i++) { \
103
      ierr = PetscStrcpy(name,N "_");CHKERRQ(ierr); \
104
      if (i == 0) { ierr = PetscStrcat(name,((PetscObject)(A))->type_name);CHKERRQ(ierr); } \
105
      else { ierr = PetscStrcat(name,"*");CHKERRQ(ierr); } \
106
      ierr = PetscStrcat(name,"_C");CHKERRQ(ierr); /* e.g., multname = "MatMatMult_seqdense_seqaij_C" */ \
107
      ierr = PetscObjectQueryFunction((PetscObject)(A),name,(void (**)(void))(R));CHKERRQ(ierr); \
108
    } \
109
    if (!*(R) && (E) == PETSC_TRUE) SETERRQ1(((PetscObject)(A))->comm,PETSC_ERR_ARG_INCOMP,N " requires compatible matrix, instead of %s",((PetscObject)(A))->type_name); \
110
  } \
111
}
112
 
113
 
114
 
2517 eromero 115
/*MC
116
   PetscObjectQueryPolymorphicFunction - Returns in R the best function for the
117
   operation F, considering the types of A and B.
118
 
119
   Synopsis:
120
   PetscObjectQueryPolymorphicFunction(PetscObject A,PetscObject B,field,const char *N,void *(*R)(void),PetscBool err)
121
 
122
   Not Collective
123
 
124
   Input Parameters:
125
+  A,B - PetscObjects that participate in the operation
126
.  field - name of the field in structure ops that contains the function pointer
127
.  N - name of routine
128
-  err - if PETSC_TRUE, PetscError is called when any function is found
129
 
130
   Output Parameters:
131
.  R - the function pointer
132
 
133
   Level: development
134
 
135
M*/
136
#define PetscObjectQueryPolymorphicFunction(A,B,F,N,R,E) { \
2533 eromero 137
  if ((A)->ops->F == (B)->ops->F && (A)->ops->F) { \
2522 eromero 138
    *(R) = (A)->ops->F; \
2517 eromero 139
  } else {  \
140
    /* dispatch based on the type of A and B */ \
2518 eromero 141
    char           name[256]; \
142
    PetscInt       i; \
2517 eromero 143
    PetscErrorCode ierr; \
144
    for (i=0, *(R)=PETSC_NULL; !*(R) && i<3; i++) { \
2518 eromero 145
      ierr = PetscStrcpy(name,N "_");CHKERRQ(ierr); \
2517 eromero 146
      if (!(i & 1)) { ierr = PetscStrcat(name,((PetscObject)(A))->type_name);CHKERRQ(ierr); } \
147
      else { ierr = PetscStrcat(name,"*");CHKERRQ(ierr); } \
148
      ierr = PetscStrcat(name,"_");CHKERRQ(ierr); \
149
      if (!(i & 2)) { ierr = PetscStrcat(name,((PetscObject)(B))->type_name);CHKERRQ(ierr); } \
150
      else { ierr = PetscStrcat(name,"*");CHKERRQ(ierr); } \
151
      ierr = PetscStrcat(name,"_C");CHKERRQ(ierr); /* e.g., multname = "MatMatMult_seqdense_seqaij_C" */ \
152
      ierr = PetscObjectQueryFunction((PetscObject)(A),name,(void (**)(void))(R));CHKERRQ(ierr); \
153
      if (!*(R)) { \
154
        ierr = PetscObjectQueryFunction((PetscObject)(B),name,(void (**)(void))(R));CHKERRQ(ierr); \
155
      } \
156
    } \
2518 eromero 157
    if (!*(R) && (E) == PETSC_TRUE) SETERRQ2(((PetscObject)(A))->comm,PETSC_ERR_ARG_INCOMP,N " requires compatible matrices, instead of %s and %s",((PetscObject)(A))->type_name,((PetscObject)(B))->type_name); \
2517 eromero 158
  } \
159
}
160
 
2852 eromero 161
PetscErrorCode  MatDensePerformReduction(MatDense A,MPI_Op op,PetscBool immediate);
2517 eromero 162
 
2852 eromero 163
#undef __FUNCT__  
164
#define __FUNCT__ "PetscCheckMatDenseForRead"
165
PETSC_STATIC_INLINE PetscErrorCode PetscCheckMatDenseForRead(MatDense A)
166
{
167
  PetscErrorCode  ierr;
168
  PetscFunctionBegin;
169
  if (!(A->is_allocated == PETSC_TRUE)) SETERRQ(((PetscObject)A)->comm,PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled matrix");
170
  if (A->is_pending && A->n_getarray == 0) {
171
    ierr = MatDensePerformReduction(PETSC_NULL,PETSC_NULL,PETSC_TRUE);CHKERRQ(ierr);
172
  }
173
  PetscFunctionReturn(0);
174
}
2517 eromero 175
 
2852 eromero 176
#undef __FUNCT__  
177
#define __FUNCT__ "PetscCheckMatDenseForWrite"
178
PETSC_STATIC_INLINE PetscErrorCode PetscCheckMatDenseForWrite(MatDense A)
179
{
180
  PetscErrorCode  ierr;
181
  ierr = MatDenseSetUpPreallocation(A);CHKERRQ(ierr);
182
  if (!(A->is_allocated == PETSC_TRUE)) SETERRQ(((PetscObject)A)->comm,PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled matrix");
183
  if (A->is_pending && A->n_getarray == 0) {
184
    ierr = MatDensePerformReduction(PETSC_NULL,PETSC_NULL,PETSC_TRUE);CHKERRQ(ierr);
185
  }
186
  PetscFunctionReturn(0);
187
}
2517 eromero 188
 
2852 eromero 189
#undef __FUNCT__  
190
#define __FUNCT__ "PetscCheckMatDenseForUpdate"
191
PETSC_STATIC_INLINE PetscErrorCode PetscCheckMatDenseForUpdate(MatDense A)
192
{
193
  PetscErrorCode  ierr;
194
  ierr = MatDenseSetUpPreallocation(A);CHKERRQ(ierr);
195
  if (!(A->is_allocated == PETSC_TRUE)) SETERRQ(((PetscObject)A)->comm,PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled matrix");
196
  if (A->is_pending && A->n_getarray == 0) {
197
    ierr = MatDensePerformReduction(PETSC_NULL,PETSC_NULL,PETSC_TRUE);CHKERRQ(ierr);
198
  }
199
  PetscFunctionReturn(0);
200
}
201
 
2517 eromero 202
#define MatDenseIsHermitian(A) (A->is_hermitian == PETSC_TRUE)
203
#define MatDenseIsTriangular(A) (A->is_triangular == PETSC_TRUE)
204
#define MatDenseIsImplicit(A) (A->is_impl == PETSC_TRUE)
205
#define MatDenseIsImplicitHermitian(A) (MatDenseIsHermitian(A) && MatDenseIsImplicit(A))
206
#define MatDenseIsExplicitHermitian(A) (MatDenseIsHermitian(A) && !MatDenseIsImplicit(A))
207
#define MatDenseIsImplicitTriangular(A) (MatDenseIsTriangular(A) && MatDenseIsImplicit(A))
208
#define MatDenseIsExplicitTriangular(A) (MatDenseIsTriangular(A) && !MatDenseIsImplicit(A))
209
#define MatDenseIsSimple(A) (!MatDenseIsHermitian(A) && !MatDenseIsTriangular(A))
2518 eromero 210
 
211
PetscErrorCode MatDenseRegisterAll(const char *path);
2544 eromero 212
extern PetscLogEvent    MATDENSE_Duplicate,MATDENSE_SetUpPreallocation,MATDENSE_MatMult,MATDENSE_Copy,MATDENSE_AXPY,MATDENSE_View,MATDENSE_Convert,MATDENSE_BlasMatMult;
2517 eromero 213
#endif