PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscsys(void) #endif { PetscErrorCode ierr; PetscFunctionBegin; /* If we got here then PETSc was properly loaded */ ierr = PetscSysInitializePackage(); CHKERRQ(ierr); ierr = PetscDrawInitializePackage(); CHKERRQ(ierr); ierr = PetscViewerInitializePackage(); CHKERRQ(ierr); ierr = PetscRandomInitializePackage(); CHKERRQ(ierr); #if defined(PETSC_USE_SINGLE_LIBRARY) ierr = PetscDLLibraryRegister_petscvec(); CHKERRQ(ierr); ierr = PetscDLLibraryRegister_petscmat(); CHKERRQ(ierr); ierr = PetscDLLibraryRegister_petscdm(); CHKERRQ(ierr); ierr = PetscDLLibraryRegister_petscksp(); CHKERRQ(ierr); ierr = PetscDLLibraryRegister_petscsnes(); CHKERRQ(ierr); ierr = PetscDLLibraryRegister_petscts(); CHKERRQ(ierr); #endif PetscFunctionReturn(0); }
PetscErrorCode PetscRandomCreate(MPI_Comm comm,PetscRandom *r) { PetscRandom rr; PetscErrorCode ierr; PetscMPIInt rank; PetscFunctionBegin; PetscValidPointer(r,3); *r = NULL; #if !defined(PETSC_USE_DYNAMIC_LIBRARIES) ierr = PetscRandomInitializePackage();CHKERRQ(ierr); #endif ierr = PetscHeaderCreate(rr,_p_PetscRandom,struct _PetscRandomOps,PETSC_RANDOM_CLASSID,"PetscRandom","Random number generator","Sys",comm,PetscRandomDestroy,0);CHKERRQ(ierr); ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); rr->data = NULL; rr->low = 0.0; rr->width = 1.0; rr->iset = PETSC_FALSE; rr->seed = 0x12345678 + 76543*rank; *r = rr; PetscFunctionReturn(0); }
PetscErrorCode PetscRandomCreate(MPI_Comm comm,PetscRandom *r) { PetscRandom rr; PetscErrorCode ierr; PetscMPIInt rank; PetscFunctionBegin; PetscValidPointer(r,3); *r = NULL; ierr = PetscRandomInitializePackage(); CHKERRQ(ierr); ierr = PetscHeaderCreate(rr,PETSC_RANDOM_CLASSID,"PetscRandom","Random number generator","Sys",comm,PetscRandomDestroy,NULL); CHKERRQ(ierr); ierr = MPI_Comm_rank(comm,&rank); CHKERRQ(ierr); rr->data = NULL; rr->low = 0.0; rr->width = 1.0; rr->iset = PETSC_FALSE; rr->seed = 0x12345678 + 76543*rank; ierr = PetscRandomSetType(rr,PETSCRANDER48); CHKERRQ(ierr); *r = rr; PetscFunctionReturn(0); }
/*@C PetscRandomRegister - Adds a new PetscRandom component implementation Not Collective Input Parameters: + name - The name of a new user-defined creation routine - create_func - The creation routine itself Notes: PetscRandomRegister() may be called multiple times to add several user-defined randome number generators Sample usage: .vb PetscRandomRegister("my_rand", MyPetscRandomtorCreate); .ve Then, your random type can be chosen with the procedural interface via .vb PetscRandomCreate(MPI_Comm, PetscRandom *); PetscRandomSetType(PetscRandom,"my_random_name"); .ve or at runtime via the option .vb -random_type my_random_name .ve Notes: For an example of the code needed to interface your own random number generator see src/sys/random/impls/rand/rand.c Level: advanced .keywords: PetscRandom, register .seealso: PetscRandomRegisterAll(), PetscRandomRegisterDestroy(), PetscRandomRegister() @*/ PetscErrorCode PetscRandomRegister(const char sname[], PetscErrorCode (*function)(PetscRandom)) { PetscErrorCode ierr; PetscFunctionBegin; ierr = PetscRandomInitializePackage();CHKERRQ(ierr); ierr = PetscFunctionListAdd(&PetscRandomList,sname,function);CHKERRQ(ierr); PetscFunctionReturn(0); }