Actual source code: dlregisvec.c

petsc-master 2019-12-08
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:   /* Process info exclusions */
 62:   PetscOptionsGetString(NULL,NULL,"-info_exclude",logList,sizeof(logList),&opt);
 63:   if (opt) {
 64:     PetscStrInList("is",logList,',',&pkg);
 65:     if (pkg) {PetscInfoDeactivateClass(IS_CLASSID);}
 66:     if (pkg) {PetscInfoDeactivateClass(IS_LTOGM_CLASSID);}
 67:     PetscStrInList("section",logList,',',&pkg);
 68:     if (pkg) {PetscInfoDeactivateClass(PETSC_SECTION_CLASSID);}
 69:     if (pkg) {PetscInfoDeactivateClass(PETSC_SECTION_SYM_CLASSID);}
 70:   }
 71:   /* Process summary exclusions */
 72:   PetscOptionsGetString(NULL,NULL,"-log_exclude",logList,sizeof(logList),&opt);
 73:   if (opt) {
 74:     PetscStrInList("is",logList,',',&pkg);
 75:     if (pkg) {PetscLogEventExcludeClass(IS_CLASSID);}
 76:     if (pkg) {PetscLogEventExcludeClass(IS_LTOGM_CLASSID);}
 77:     PetscStrInList("section",logList,',',&pkg);
 78:     if (pkg) {PetscLogEventExcludeClass(PETSC_SECTION_CLASSID);}
 79:     if (pkg) {PetscLogEventExcludeClass(PETSC_SECTION_SYM_CLASSID);}
 80:   }
 81:   /* Register package finalizer */
 82:   PetscRegisterFinalize(ISFinalizePackage);
 83:   return(0);
 84: }

 86: extern MPI_Op PetscSplitReduction_Op;

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

 92: */
 93: MPI_Op MPIU_MAXINDEX_OP = 0;
 94: MPI_Op MPIU_MININDEX_OP = 0;

 96: static void MPIAPI MPIU_MaxIndex_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype)
 97: {
 98:   PetscReal *xin = (PetscReal*)in,*xout = (PetscReal*)out;

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

114: static void MPIAPI MPIU_MinIndex_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype)
115: {
116:   PetscReal *xin = (PetscReal*)in,*xout = (PetscReal*)out;

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

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

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

137: static PetscBool  VecPackageInitialized = PETSC_FALSE;

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

144:   Level: developer

146: .seealso: PetscInitialize()
147: @*/
148: PetscErrorCode  VecInitializePackage(void)
149: {
150:   char           logList[256];
151:   PetscBool      opt,pkg;
153:   PetscInt       i;

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

206:   /* Mark non-collective events */
207:   PetscLogEventSetCollective(VEC_SetValues,           PETSC_FALSE);
208: #if defined(PETSC_HAVE_VIENNACL)
209:   PetscLogEventSetCollective(VEC_ViennaCLCopyToGPU,   PETSC_FALSE);
210:   PetscLogEventSetCollective(VEC_ViennaCLCopyFromGPU, PETSC_FALSE);
211: #endif
212: #if defined(PETSC_HAVE_CUDA)
213:   PetscLogEventSetCollective(VEC_CUDACopyToGPU,       PETSC_FALSE);
214:   PetscLogEventSetCollective(VEC_CUDACopyFromGPU,     PETSC_FALSE);
215:   PetscLogEventSetCollective(VEC_CUDACopyToGPUSome,   PETSC_FALSE);
216:   PetscLogEventSetCollective(VEC_CUDACopyFromGPUSome, PETSC_FALSE);
217: #endif
218:   /* Turn off high traffic events by default */
219:   PetscLogEventSetActiveAll(VEC_SetValues, PETSC_FALSE);

221:   /* Process info exclusions */
222:   PetscOptionsGetString(NULL,NULL,"-info_exclude",logList,sizeof(logList),&opt);
223:   if (opt) {
224:     PetscStrInList("vec",logList,',',&pkg);
225:     if (pkg) {PetscInfoDeactivateClass(VEC_CLASSID);}
226:     if (pkg) {PetscInfoDeactivateClass(VEC_SCATTER_CLASSID);}
227:   }

229:   /* Process summary exclusions */
230:   PetscOptionsGetString(NULL,NULL,"-log_exclude",logList,sizeof(logList),&opt);
231:   if (opt) {
232:     PetscStrInList("vec",logList,',',&pkg);
233:     if (pkg) {PetscLogEventExcludeClass(VEC_CLASSID);}
234:     if (pkg) {PetscLogEventExcludeClass(VEC_SCATTER_CLASSID);}
235:   }

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

244:   /* Register the different norm types for cached norms */
245:   for (i=0; i<4; i++) {
246:     PetscObjectComposedDataRegister(NormIds+i);
247:   }

249:   /* Register package finalizer */
250:   PetscRegisterFinalize(VecFinalizePackage);
251:   return(0);
252: }

254: /*@C
255:   VecFinalizePackage - This function finalizes everything in the Vec package. It is called
256:   from PetscFinalize().

258:   Level: developer

260: .seealso: PetscInitialize()
261: @*/
262: PetscErrorCode  VecFinalizePackage(void)
263: {

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

280: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
281: /*
282:   PetscDLLibraryRegister - This function is called when the dynamic library it is in is opened.

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

286:  */
287: PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscvec(void)
288: {

292:   PetscSFInitializePackage();
293:   ISInitializePackage();
294:   AOInitializePackage();
295:   VecInitializePackage();
296:   PFInitializePackage();
297:   return(0);
298: }

300: #endif /* PETSC_HAVE_DYNAMIC_LIBRARIES */