Actual source code: dlregisvec.c

petsc-3.13.4 2020-08-01
Report Typos and Errors

  2:  #include <petsc/private/vecimpl.h>
  3:  #include <petsc/private/isimpl.h>
  4:  #include <petscpf.h>
  5:  #include <petscsf.h>
  6:  #include <petscsection.h>
  7:  #include <petscao.h>

  9: static PetscBool         ISPackageInitialized = PETSC_FALSE;
 10: extern PetscFunctionList ISLocalToGlobalMappingList;
 11: const char       *ISInfos[] = {"SORTED", "UNIQUE", "PERMUTATION", "INTERVAL", "IDENTITY", "ISInfo", "IS_",0};

 13: /*@C
 14:   ISFinalizePackage - This function destroys everything in the IS package. It is
 15:   called from PetscFinalize().

 17:   Level: developer

 19: .seealso: PetscFinalize()
 20: @*/
 21: PetscErrorCode  ISFinalizePackage(void)
 22: {

 26:   PetscFunctionListDestroy(&ISList);
 27:   PetscFunctionListDestroy(&ISLocalToGlobalMappingList);
 28:   PetscFunctionListDestroy(&PetscSectionSymList);
 29:   ISPackageInitialized                    = PETSC_FALSE;
 30:   ISRegisterAllCalled                     = PETSC_FALSE;
 31:   ISLocalToGlobalMappingRegisterAllCalled = PETSC_FALSE;
 32:   return(0);
 33: }

 35: /*@C
 36:       ISInitializePackage - This function initializes everything in the IS package. It is called
 37:   from PetscDLLibraryRegister_petscvec() when using dynamic libraries, and on the first call to ISCreateXXXX()
 38:   when using shared or static libraries.

 40:   Level: developer

 42: .seealso: PetscInitialize()
 43: @*/
 44: PetscErrorCode  ISInitializePackage(void)
 45: {
 46:   char           logList[256];
 47:   PetscBool      opt,pkg;

 51:   if (ISPackageInitialized) return(0);
 52:   ISPackageInitialized = PETSC_TRUE;
 53:   /* Register Classes */
 54:   PetscClassIdRegister("Index Set",&IS_CLASSID);
 55:   PetscClassIdRegister("IS L to G Mapping",&IS_LTOGM_CLASSID);
 56:   PetscClassIdRegister("Section",&PETSC_SECTION_CLASSID);
 57:   PetscClassIdRegister("Section Symmetry",&PETSC_SECTION_SYM_CLASSID);
 58:   /* Register Constructors */
 59:   ISRegisterAll();
 60:   ISLocalToGlobalMappingRegisterAll();
 61:   /* Register Events */
 62:   PetscLogEventRegister("ISView",IS_CLASSID,&IS_View);
 63:   PetscLogEventRegister("ISLoad",IS_CLASSID,&IS_Load);
 64:   /* Process Info */
 65:   {
 66:     PetscClassId  classids[4];

 68:     classids[0] = IS_CLASSID;
 69:     classids[1] = IS_LTOGM_CLASSID;
 70:     classids[2] = PETSC_SECTION_CLASSID;
 71:     classids[3] = PETSC_SECTION_SYM_CLASSID;
 72:     PetscInfoProcessClass("is", 2, classids);
 73:     PetscInfoProcessClass("section", 2, &classids[2]);
 74:   }
 75:   /* Process summary exclusions */
 76:   PetscOptionsGetString(NULL,NULL,"-log_exclude",logList,sizeof(logList),&opt);
 77:   if (opt) {
 78:     PetscStrInList("is",logList,',',&pkg);
 79:     if (pkg) {PetscLogEventExcludeClass(IS_CLASSID);}
 80:     if (pkg) {PetscLogEventExcludeClass(IS_LTOGM_CLASSID);}
 81:     PetscStrInList("section",logList,',',&pkg);
 82:     if (pkg) {PetscLogEventExcludeClass(PETSC_SECTION_CLASSID);}
 83:     if (pkg) {PetscLogEventExcludeClass(PETSC_SECTION_SYM_CLASSID);}
 84:   }
 85:   /* Register package finalizer */
 86:   PetscRegisterFinalize(ISFinalizePackage);
 87:   return(0);
 88: }

 90: extern MPI_Op PetscSplitReduction_Op;

 92: /*
 93:        These two functions are the MPI reduction operation used for max and min with index
 94:    A call to MPI_Op_create() converts the function Vec[Max,Min]_Local() to the MPI operator Vec[Max,Min]_Local_Op.

 96: */
 97: MPI_Op MPIU_MAXINDEX_OP = 0;
 98: MPI_Op MPIU_MININDEX_OP = 0;

100: static void MPIAPI MPIU_MaxIndex_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype)
101: {
102:   PetscReal *xin = (PetscReal*)in,*xout = (PetscReal*)out;

105:   if (*datatype != MPIU_REAL) {
106:     (*PetscErrorPrintf)("Can only handle MPIU_REAL data types");
107:     PETSCABORT(MPI_COMM_SELF,PETSC_ERR_ARG_WRONG);
108:   }
109:   if (xin[0] > xout[0]) {
110:     xout[0] = xin[0];
111:     xout[1] = xin[1];
112:   } else if (xin[0] == xout[0]) {
113:     xout[1] = PetscMin(xin[1],xout[1]);
114:   }
115:   PetscFunctionReturnVoid(); /* cannot return a value */
116: }

118: static void MPIAPI MPIU_MinIndex_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype)
119: {
120:   PetscReal *xin = (PetscReal*)in,*xout = (PetscReal*)out;

123:   if (*datatype != MPIU_REAL) {
124:     (*PetscErrorPrintf)("Can only handle MPIU_REAL data types");
125:     PETSCABORT(MPI_COMM_SELF,PETSC_ERR_ARG_WRONG);
126:   }
127:   if (xin[0] < xout[0]) {
128:     xout[0] = xin[0];
129:     xout[1] = xin[1];
130:   } else if (xin[0] == xout[0]) {
131:     xout[1] = PetscMin(xin[1],xout[1]);
132:   }
133:   PetscFunctionReturnVoid();
134: }

136: PETSC_EXTERN void MPIAPI PetscSplitReduction_Local(void*,void*,PetscMPIInt*,MPI_Datatype*);

138: const char *const NormTypes[] = {"1","2","FROBENIUS","INFINITY","1_AND_2","NormType","NORM_",0};
139: PetscInt          NormIds[7];  /* map from NormType to IDs used to cache Normvalues */

141: static PetscBool  VecPackageInitialized = PETSC_FALSE;

143: /*@C
144:   VecInitializePackage - This function initializes everything in the Vec package. It is called
145:   from PetscDLLibraryRegister_petscvec() when using dynamic libraries, and on the first call to VecCreate()
146:   when using shared or static libraries.

148:   Level: developer

150: .seealso: PetscInitialize()
151: @*/
152: PetscErrorCode  VecInitializePackage(void)
153: {
154:   char           logList[256];
155:   PetscBool      opt,pkg;
157:   PetscInt       i;

160:   if (VecPackageInitialized) return(0);
161:   VecPackageInitialized = PETSC_TRUE;
162:   /* Initialize subpackage */
163:   VecScatterInitializePackage();
164:   /* Register Classes */
165:   PetscClassIdRegister("Vector",&VEC_CLASSID);
166:   /* Register Constructors */
167:   VecRegisterAll();
168:   /* Register Events */
169:   PetscLogEventRegister("VecView",          VEC_CLASSID,&VEC_View);
170:   PetscLogEventRegister("VecMax",           VEC_CLASSID,&VEC_Max);
171:   PetscLogEventRegister("VecMin",           VEC_CLASSID,&VEC_Min);
172:   PetscLogEventRegister("VecDot",           VEC_CLASSID,&VEC_Dot);
173:   PetscLogEventRegister("VecDotNorm2",      VEC_CLASSID,&VEC_DotNorm2);
174:   PetscLogEventRegister("VecMDot",          VEC_CLASSID,&VEC_MDot);
175:   PetscLogEventRegister("VecTDot",          VEC_CLASSID,&VEC_TDot);
176:   PetscLogEventRegister("VecMTDot",         VEC_CLASSID,&VEC_MTDot);
177:   PetscLogEventRegister("VecNorm",          VEC_CLASSID,&VEC_Norm);
178:   PetscLogEventRegister("VecScale",         VEC_CLASSID,&VEC_Scale);
179:   PetscLogEventRegister("VecCopy",          VEC_CLASSID,&VEC_Copy);
180:   PetscLogEventRegister("VecSet",           VEC_CLASSID,&VEC_Set);
181:   PetscLogEventRegister("VecAXPY",          VEC_CLASSID,&VEC_AXPY);
182:   PetscLogEventRegister("VecAYPX",          VEC_CLASSID,&VEC_AYPX);
183:   PetscLogEventRegister("VecAXPBYCZ",       VEC_CLASSID,&VEC_AXPBYPCZ);
184:   PetscLogEventRegister("VecWAXPY",         VEC_CLASSID,&VEC_WAXPY);
185:   PetscLogEventRegister("VecMAXPY",         VEC_CLASSID,&VEC_MAXPY);
186:   PetscLogEventRegister("VecSwap",          VEC_CLASSID,&VEC_Swap);
187:   PetscLogEventRegister("VecOps",           VEC_CLASSID,&VEC_Ops);
188:   PetscLogEventRegister("VecAssemblyBegin", VEC_CLASSID,&VEC_AssemblyBegin);
189:   PetscLogEventRegister("VecAssemblyEnd",   VEC_CLASSID,&VEC_AssemblyEnd);
190:   PetscLogEventRegister("VecPointwiseMult", VEC_CLASSID,&VEC_PointwiseMult);
191:   PetscLogEventRegister("VecSetValues",     VEC_CLASSID,&VEC_SetValues);
192:   PetscLogEventRegister("VecLoad",          VEC_CLASSID,&VEC_Load);
193:   PetscLogEventRegister("VecScatterBegin",  VEC_CLASSID,&VEC_ScatterBegin);
194:   PetscLogEventRegister("VecScatterEnd  ",  VEC_CLASSID,&VEC_ScatterEnd);
195:   PetscLogEventRegister("VecSetRandom",     VEC_CLASSID,&VEC_SetRandom);
196:   PetscLogEventRegister("VecReduceArith",   VEC_CLASSID,&VEC_ReduceArithmetic);
197:   PetscLogEventRegister("VecReduceComm",    VEC_CLASSID,&VEC_ReduceCommunication);
198:   PetscLogEventRegister("VecReduceBegin",   VEC_CLASSID,&VEC_ReduceBegin);
199:   PetscLogEventRegister("VecReduceEnd",     VEC_CLASSID,&VEC_ReduceEnd);
200:   PetscLogEventRegister("VecNormalize",     VEC_CLASSID,&VEC_Normalize);
201: #if defined(PETSC_HAVE_VIENNACL)
202:   PetscLogEventRegister("VecVCLCopyTo",     VEC_CLASSID,&VEC_ViennaCLCopyToGPU);
203:   PetscLogEventRegister("VecVCLCopyFrom",   VEC_CLASSID,&VEC_ViennaCLCopyFromGPU);
204: #endif
205: #if defined(PETSC_HAVE_CUDA)
206:   PetscLogEventRegister("VecCUDACopyTo",    VEC_CLASSID,&VEC_CUDACopyToGPU);
207:   PetscLogEventRegister("VecCUDACopyFrom",  VEC_CLASSID,&VEC_CUDACopyFromGPU);
208:   PetscLogEventRegister("VecCopyToSome",    VEC_CLASSID,&VEC_CUDACopyToGPUSome);
209:   PetscLogEventRegister("VecCopyFromSome",  VEC_CLASSID,&VEC_CUDACopyFromGPUSome);
210: #endif

212:   /* Mark non-collective events */
213:   PetscLogEventSetCollective(VEC_SetValues,           PETSC_FALSE);
214: #if defined(PETSC_HAVE_VIENNACL)
215:   PetscLogEventSetCollective(VEC_ViennaCLCopyToGPU,   PETSC_FALSE);
216:   PetscLogEventSetCollective(VEC_ViennaCLCopyFromGPU, PETSC_FALSE);
217: #endif
218: #if defined(PETSC_HAVE_CUDA)
219:   PetscLogEventSetCollective(VEC_CUDACopyToGPU,       PETSC_FALSE);
220:   PetscLogEventSetCollective(VEC_CUDACopyFromGPU,     PETSC_FALSE);
221:   PetscLogEventSetCollective(VEC_CUDACopyToGPUSome,   PETSC_FALSE);
222:   PetscLogEventSetCollective(VEC_CUDACopyFromGPUSome, PETSC_FALSE);
223: #endif
224:   /* Turn off high traffic events by default */
225:   PetscLogEventSetActiveAll(VEC_SetValues, PETSC_FALSE);
226:   /* Process Info */
227:   {
228:     PetscClassId  classids[1];

230:     classids[0] = VEC_CLASSID;
231:     PetscInfoProcessClass("vec", 1, classids);
232:   }
233:   /* Process summary exclusions */
234:   PetscOptionsGetString(NULL,NULL,"-log_exclude",logList,sizeof(logList),&opt);
235:   if (opt) {
236:     PetscStrInList("vec",logList,',',&pkg);
237:     if (pkg) {PetscLogEventExcludeClass(VEC_CLASSID);}
238:     if (pkg) {PetscLogEventExcludeClass(VEC_SCATTER_CLASSID);}
239:   }

241:   /*
242:     Create the special MPI reduction operation that may be used by VecNorm/DotBegin()
243:   */
244:   MPI_Op_create(PetscSplitReduction_Local,1,&PetscSplitReduction_Op);
245:   MPI_Op_create(MPIU_MaxIndex_Local,2,&MPIU_MAXINDEX_OP);
246:   MPI_Op_create(MPIU_MinIndex_Local,2,&MPIU_MININDEX_OP);

248:   /* Register the different norm types for cached norms */
249:   for (i=0; i<4; i++) {
250:     PetscObjectComposedDataRegister(NormIds+i);
251:   }

253:   /* Register package finalizer */
254:   PetscRegisterFinalize(VecFinalizePackage);
255:   return(0);
256: }

258: /*@C
259:   VecFinalizePackage - This function finalizes everything in the Vec package. It is called
260:   from PetscFinalize().

262:   Level: developer

264: .seealso: PetscInitialize()
265: @*/
266: PetscErrorCode  VecFinalizePackage(void)
267: {

271:   PetscFunctionListDestroy(&VecList);
272:   PetscFunctionListDestroy(&VecScatterList);
273:   MPI_Op_free(&PetscSplitReduction_Op);
274:   MPI_Op_free(&MPIU_MAXINDEX_OP);
275:   MPI_Op_free(&MPIU_MININDEX_OP);
276:   if (Petsc_Reduction_keyval != MPI_KEYVAL_INVALID) {
277:     MPI_Comm_free_keyval(&Petsc_Reduction_keyval);
278:   }
279:   VecPackageInitialized = PETSC_FALSE;
280:   VecRegisterAllCalled  = PETSC_FALSE;
281:   return(0);
282: }

284: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
285: /*
286:   PetscDLLibraryRegister - This function is called when the dynamic library it is in is opened.

288:   This one registers all the methods that are in the basic PETSc Vec library.

290:  */
291: PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscvec(void)
292: {

296:   PetscSFInitializePackage();
297:   ISInitializePackage();
298:   AOInitializePackage();
299:   VecInitializePackage();
300:   PFInitializePackage();
301:   return(0);
302: }

304: #endif /* PETSC_HAVE_DYNAMIC_LIBRARIES */