Date: 2022-03-31T04:46:22+00:00

Actual source code: dlregisvec.c

      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_",NULL};

     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: {
     23:   PetscFunctionListDestroy(&ISList);
     24:   PetscFunctionListDestroy(&ISLocalToGlobalMappingList);
     25:   PetscFunctionListDestroy(&PetscSectionSymList);
     26:   ISPackageInitialized                    = PETSC_FALSE;
     27:   ISRegisterAllCalled                     = PETSC_FALSE;
     28:   ISLocalToGlobalMappingRegisterAllCalled = PETSC_FALSE;
     29:   return 0;
     30: }

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

     37:   Level: developer

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

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

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

     85: extern MPI_Op PetscSplitReduction_Op;

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

     91: */
     92: MPI_Op MPIU_MAXLOC = 0;
     93: MPI_Op MPIU_MINLOC = 0;

     95: static void MPIAPI MPIU_MaxIndex_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype)
     96: {
     97:   struct PetscRealInt { PetscReal v; PetscInt i; };
     98:   struct PetscRealInt *xin = (struct PetscRealInt*)in;
     99:   struct PetscRealInt *xout = (struct PetscRealInt*)out;
    100:   int                 c;

    102:   if (*datatype != MPIU_REAL_INT) {
    103:     (*PetscErrorPrintf)("Can only handle MPIU_REAL_INT data types");
    104:     PETSCABORT(MPI_COMM_SELF,PETSC_ERR_ARG_WRONG);
    105:   }
    106:   for (c = 0; c < *cnt; c++) {
    107:     if (xin[c].v > xout[c].v) {
    108:       xout[c].v = xin[c].v;
    109:       xout[c].i = xin[c].i;
    110:     } else if (xin[c].v == xout[c].v) {
    111:       xout[c].i = PetscMin(xin[c].i,xout[c].i);
    112:     }
    113:   }
    114:   return; /* cannot return a value */
    115: }

    117: static void MPIAPI MPIU_MinIndex_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype)
    118: {
    119:   struct PetscRealInt { PetscReal v; PetscInt i; };
    120:   struct PetscRealInt *xin = (struct PetscRealInt*)in;
    121:   struct PetscRealInt *xout = (struct PetscRealInt*)out;
    122:   int                 c;

    124:   if (*datatype != MPIU_REAL_INT) {
    125:     (*PetscErrorPrintf)("Can only handle MPIU_REAL_INT data types");
    126:     PETSCABORT(MPI_COMM_SELF,PETSC_ERR_ARG_WRONG);
    127:   }
    128:   for (c = 0; c < *cnt; c++) {
    129:     if (xin[c].v < xout[c].v) {
    130:       xout[c].v = xin[c].v;
    131:       xout[c].i = xin[c].i;
    132:     } else if (xin[c].v == xout[c].v) {
    133:       xout[c].i = PetscMin(xin[c].i,xout[c].i);
    134:     }
    135:   }
    136:   return; /* cannot return a value */
    137: }

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

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

    144: static PetscBool  VecPackageInitialized = PETSC_FALSE;

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

    151:   Level: developer

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

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

    217:   /* Mark non-collective events */
    218:   PetscLogEventSetCollective(VEC_SetValues,           PETSC_FALSE);
    219: #if defined(PETSC_HAVE_VIENNACL)
    220:   PetscLogEventSetCollective(VEC_ViennaCLCopyToGPU,   PETSC_FALSE);
    221:   PetscLogEventSetCollective(VEC_ViennaCLCopyFromGPU, PETSC_FALSE);
    222: #endif
    223: #if defined(PETSC_HAVE_CUDA)
    224:   PetscLogEventSetCollective(VEC_CUDACopyToGPU,       PETSC_FALSE);
    225:   PetscLogEventSetCollective(VEC_CUDACopyFromGPU,     PETSC_FALSE);
    226:   PetscLogEventSetCollective(VEC_CUDACopyToGPUSome,   PETSC_FALSE);
    227:   PetscLogEventSetCollective(VEC_CUDACopyFromGPUSome, PETSC_FALSE);
    228: #endif
    229: #if defined(PETSC_HAVE_HIP)
    230:   PetscLogEventSetCollective(VEC_HIPCopyToGPU,       PETSC_FALSE);
    231:   PetscLogEventSetCollective(VEC_HIPCopyFromGPU,     PETSC_FALSE);
    232:   PetscLogEventSetCollective(VEC_HIPCopyToGPUSome,   PETSC_FALSE);
    233:   PetscLogEventSetCollective(VEC_HIPCopyFromGPUSome, PETSC_FALSE);
    234: #endif
    235:   /* Turn off high traffic events by default */
    236:   PetscLogEventSetActiveAll(VEC_SetValues, PETSC_FALSE);
    237:   /* Process Info */
    238:   {
    239:     PetscClassId  classids[1];

    241:     classids[0] = VEC_CLASSID;
    242:     PetscInfoProcessClass("vec", 1, classids);
    243:   }
    244:   /* Process summary exclusions */
    245:   PetscOptionsGetString(NULL,NULL,"-log_exclude",logList,sizeof(logList),&opt);
    246:   if (opt) {
    247:     PetscStrInList("vec",logList,',',&pkg);
    248:     if (pkg) PetscLogEventExcludeClass(VEC_CLASSID);
    249:     if (pkg) PetscLogEventExcludeClass(PETSCSF_CLASSID);
    250:   }

    252:   /*
    253:     Create the special MPI reduction operation that may be used by VecNorm/DotBegin()
    254:   */
    255:   MPI_Op_create(PetscSplitReduction_Local,1,&PetscSplitReduction_Op);
    256:   MPI_Op_create(MPIU_MaxIndex_Local,1,&MPIU_MAXLOC);
    257:   MPI_Op_create(MPIU_MinIndex_Local,1,&MPIU_MINLOC);

    259:   /* Register the different norm types for cached norms */
    260:   for (i=0; i<4; i++) {
    261:     PetscObjectComposedDataRegister(NormIds+i);
    262:   }

    264:   /* Register package finalizer */
    265:   PetscRegisterFinalize(VecFinalizePackage);
    266:   return 0;
    267: }

    269: /*@C
    270:   VecFinalizePackage - This function finalizes everything in the Vec package. It is called
    271:   from PetscFinalize().

    273:   Level: developer

    275: .seealso: PetscInitialize()
    276: @*/
    277: PetscErrorCode  VecFinalizePackage(void)
    278: {
    279:   PetscFunctionListDestroy(&VecList);
    280:   MPI_Op_free(&PetscSplitReduction_Op);
    281:   MPI_Op_free(&MPIU_MAXLOC);
    282:   MPI_Op_free(&MPIU_MINLOC);
    283:   if (Petsc_Reduction_keyval != MPI_KEYVAL_INVALID) {
    284:     MPI_Comm_free_keyval(&Petsc_Reduction_keyval);
    285:   }
    286:   VecPackageInitialized = PETSC_FALSE;
    287:   VecRegisterAllCalled  = PETSC_FALSE;
    288:   return 0;
    289: }

    291: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
    292: /*
    293:   PetscDLLibraryRegister - This function is called when the dynamic library it is in is opened.

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

    297:  */
    298: PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscvec(void)
    299: {
    300:   PetscSFInitializePackage();
    301:   ISInitializePackage();
    302:   AOInitializePackage();
    303:   VecInitializePackage();
    304:   PFInitializePackage();
    305:   return 0;
    306: }

    308: #endif /* PETSC_HAVE_DYNAMIC_LIBRARIES */