Date: 2022-03-04T17:37: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: {

     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_MAXLOC = 0;
     98: MPI_Op MPIU_MINLOC = 0;

    100: static void MPIAPI MPIU_MaxIndex_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype)
    101: {
    102:   struct PetscRealInt { PetscReal v; PetscInt i; };
    103:   struct PetscRealInt *xin = (struct PetscRealInt*)in;
    104:   struct PetscRealInt *xout = (struct PetscRealInt*)out;
    105:   int                 c;

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

    123: static void MPIAPI MPIU_MinIndex_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype)
    124: {
    125:   struct PetscRealInt { PetscReal v; PetscInt i; };
    126:   struct PetscRealInt *xin = (struct PetscRealInt*)in;
    127:   struct PetscRealInt *xout = (struct PetscRealInt*)out;
    128:   int                 c;

    131:   if (*datatype != MPIU_REAL_INT) {
    132:     (*PetscErrorPrintf)("Can only handle MPIU_REAL_INT data types");
    133:     PETSCABORT(MPI_COMM_SELF,PETSC_ERR_ARG_WRONG);
    134:   }
    135:   for (c = 0; c < *cnt; c++) {
    136:     if (xin[c].v < xout[c].v) {
    137:       xout[c].v = xin[c].v;
    138:       xout[c].i = xin[c].i;
    139:     } else if (xin[c].v == xout[c].v) {
    140:       xout[c].i = PetscMin(xin[c].i,xout[c].i);
    141:     }
    142:   }
    143:   PetscFunctionReturnVoid(); /* cannot return a value */
    144: }

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

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

    151: static PetscBool  VecPackageInitialized = PETSC_FALSE;

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

    158:   Level: developer

    160: .seealso: PetscInitialize()
    161: @*/
    162: PetscErrorCode  VecInitializePackage(void)
    163: {
    164:   char           logList[256];
    165:   PetscBool      opt,pkg;
    167:   PetscInt       i;

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

    226:   /* Mark non-collective events */
    227:   PetscLogEventSetCollective(VEC_SetValues,           PETSC_FALSE);
    228: #if defined(PETSC_HAVE_VIENNACL)
    229:   PetscLogEventSetCollective(VEC_ViennaCLCopyToGPU,   PETSC_FALSE);
    230:   PetscLogEventSetCollective(VEC_ViennaCLCopyFromGPU, PETSC_FALSE);
    231: #endif
    232: #if defined(PETSC_HAVE_CUDA)
    233:   PetscLogEventSetCollective(VEC_CUDACopyToGPU,       PETSC_FALSE);
    234:   PetscLogEventSetCollective(VEC_CUDACopyFromGPU,     PETSC_FALSE);
    235:   PetscLogEventSetCollective(VEC_CUDACopyToGPUSome,   PETSC_FALSE);
    236:   PetscLogEventSetCollective(VEC_CUDACopyFromGPUSome, PETSC_FALSE);
    237: #endif
    238: #if defined(PETSC_HAVE_HIP)
    239:   PetscLogEventSetCollective(VEC_HIPCopyToGPU,       PETSC_FALSE);
    240:   PetscLogEventSetCollective(VEC_HIPCopyFromGPU,     PETSC_FALSE);
    241:   PetscLogEventSetCollective(VEC_HIPCopyToGPUSome,   PETSC_FALSE);
    242:   PetscLogEventSetCollective(VEC_HIPCopyFromGPUSome, PETSC_FALSE);
    243: #endif
    244:   /* Turn off high traffic events by default */
    245:   PetscLogEventSetActiveAll(VEC_SetValues, PETSC_FALSE);
    246:   /* Process Info */
    247:   {
    248:     PetscClassId  classids[1];

    250:     classids[0] = VEC_CLASSID;
    251:     PetscInfoProcessClass("vec", 1, classids);
    252:   }
    253:   /* Process summary exclusions */
    254:   PetscOptionsGetString(NULL,NULL,"-log_exclude",logList,sizeof(logList),&opt);
    255:   if (opt) {
    256:     PetscStrInList("vec",logList,',',&pkg);
    257:     if (pkg) {PetscLogEventExcludeClass(VEC_CLASSID);}
    258:     if (pkg) {PetscLogEventExcludeClass(PETSCSF_CLASSID);}
    259:   }

    261:   /*
    262:     Create the special MPI reduction operation that may be used by VecNorm/DotBegin()
    263:   */
    264:   MPI_Op_create(PetscSplitReduction_Local,1,&PetscSplitReduction_Op);
    265:   MPI_Op_create(MPIU_MaxIndex_Local,1,&MPIU_MAXLOC);
    266:   MPI_Op_create(MPIU_MinIndex_Local,1,&MPIU_MINLOC);

    268:   /* Register the different norm types for cached norms */
    269:   for (i=0; i<4; i++) {
    270:     PetscObjectComposedDataRegister(NormIds+i);
    271:   }

    273:   /* Register package finalizer */
    274:   PetscRegisterFinalize(VecFinalizePackage);
    275:   return(0);
    276: }

    278: /*@C
    279:   VecFinalizePackage - This function finalizes everything in the Vec package. It is called
    280:   from PetscFinalize().

    282:   Level: developer

    284: .seealso: PetscInitialize()
    285: @*/
    286: PetscErrorCode  VecFinalizePackage(void)
    287: {

    291:   PetscFunctionListDestroy(&VecList);
    292:   MPI_Op_free(&PetscSplitReduction_Op);
    293:   MPI_Op_free(&MPIU_MAXLOC);
    294:   MPI_Op_free(&MPIU_MINLOC);
    295:   if (Petsc_Reduction_keyval != MPI_KEYVAL_INVALID) {
    296:     MPI_Comm_free_keyval(&Petsc_Reduction_keyval);
    297:   }
    298:   VecPackageInitialized = PETSC_FALSE;
    299:   VecRegisterAllCalled  = PETSC_FALSE;
    300:   return(0);
    301: }

    303: #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
    304: /*
    305:   PetscDLLibraryRegister - This function is called when the dynamic library it is in is opened.

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

    309:  */
    310: PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscvec(void)
    311: {

    315:   PetscSFInitializePackage();
    316:   ISInitializePackage();
    317:   AOInitializePackage();
    318:   VecInitializePackage();
    319:   PFInitializePackage();
    320:   return(0);
    321: }

    323: #endif /* PETSC_HAVE_DYNAMIC_LIBRARIES */