Actual source code: dlregisthreadcomm.c
petsc-3.5.4 2015-05-23
1: #include <petsc-private/threadcommimpl.h>
3: static PetscBool PetscThreadCommPackageInitialized = PETSC_FALSE;
5: extern PetscErrorCode PetscThreadCommDetach(MPI_Comm);
6: extern PetscBool PetscThreadCommRegisterAllCalled;
10: /*@C
11: PetscThreadCommFinalizePackage - Finalize PetscThreadComm package, called from PetscFinalize()
13: Logically collective
15: Level: developer
17: .seealso: PetscThreadCommInitializePackage()
18: @*/
19: PetscErrorCode PetscThreadCommFinalizePackage(void)
20: {
24: PetscFunctionListDestroy(&PetscThreadCommList);
25: MPI_Keyval_free(&Petsc_ThreadComm_keyval);
26: PetscThreadCommPackageInitialized = PETSC_FALSE;
27: PetscThreadCommRegisterAllCalled = PETSC_FALSE;
28: return(0);
29: }
33: /*
34: This frees the thread communicator attached to MPI_Comm
36: This is called by MPI, not by users. This is called when MPI_Comm_free() is called on the communicator.
38: Note: this is declared extern "C" because it is passed to MPI_Keyval_create()
39: */
40: PETSC_EXTERN PetscMPIInt MPIAPI Petsc_CopyThreadComm(MPI_Comm comm,PetscMPIInt keyval,void *extra_state,void *attr_in,void *attr_out,int *flag)
41: {
42: PetscErrorCode ierr;
43: PetscThreadComm tcomm = (PetscThreadComm)attr_in;
46: tcomm->refct++;
47: *(void**)attr_out = tcomm;
49: *flag = 1;
50: PetscInfo1(0,"Copying thread communicator data in an MPI_Comm %ld\n",(long)comm);
51: if (ierr) PetscFunctionReturn((PetscMPIInt)ierr);
52: return(0);
53: }
57: /*
58: This frees the thread communicator attached to MPI_Comm
60: This is called by MPI, not by users. This is called when MPI_Comm_free() is called on the communicator.
62: Note: this is declared extern "C" because it is passed to MPI_Keyval_create()
63: */
64: PETSC_EXTERN PetscMPIInt MPIAPI Petsc_DelThreadComm(MPI_Comm comm,PetscMPIInt keyval,void *attr,void *extra_state)
65: {
69: PetscThreadCommDestroy((PetscThreadComm*)&attr);
70: PetscInfo1(0,"Deleting thread communicator data in an MPI_Comm %ld\n",(long)comm);if (ierr) PetscFunctionReturn((PetscMPIInt)ierr);
71: return(0);
72: }
76: /*@C
77: PetscThreadCommInitializePackage - Initializes ThreadComm package
79: Logically collective
81: Level: developer
83: .seealso: PetscThreadCommFinalizePackage()
84: @*/
85: PetscErrorCode PetscThreadCommInitializePackage(void)
86: {
90: if (PetscThreadCommPackageInitialized) return(0);
92: if (Petsc_ThreadComm_keyval == MPI_KEYVAL_INVALID) {
93: MPI_Keyval_create(Petsc_CopyThreadComm,Petsc_DelThreadComm,&Petsc_ThreadComm_keyval,(void*)0);
94: }
96: PetscGetNCores(NULL);
98: PetscLogEventRegister("ThreadCommRunKer", 0, &ThreadComm_RunKernel);
99: PetscLogEventRegister("ThreadCommBarrie", 0, &ThreadComm_Barrier);
101: PetscThreadCommPackageInitialized = PETSC_TRUE;
103: PetscRegisterFinalize(PetscThreadCommFinalizePackage);
104: return(0);
105: }