Date: 2013-07-02T14:39:35+00:00

Actual source code: tcopenmp.c
petsc-3.4.2 2013-07-02

      1: #define PETSC_DESIRE_FEATURE_TEST_MACROS
      2: #include <../src/sys/threadcomm/impls/openmp/tcopenmpimpl.h>
      3: #include <omp.h>

      5: PetscErrorCode PetscThreadCommGetRank_OpenMP(PetscInt *trank)
      6: {
      7:   *trank =  omp_get_thread_num();
      8:   return 0;
      9: }

     13: PETSC_EXTERN PetscErrorCode PetscThreadCommCreate_OpenMP(PetscThreadComm tcomm)
     14: {

     18:   PetscStrcpy(tcomm->type,OPENMP);
     19:   tcomm->ops->runkernel = PetscThreadCommRunKernel_OpenMP;
     20:   tcomm->ops->getrank   = PetscThreadCommGetRank_OpenMP;
     21: #pragma omp parallel num_threads(tcomm->nworkThreads) shared(tcomm)
     22:   {
     23: #if defined(PETSC_HAVE_SCHED_CPU_SET_T)
     24:     cpu_set_t mset;
     25:     PetscInt  ncores, icorr,trank;
     26:     PetscGetNCores(&ncores);
     27:     CPU_ZERO(&mset);
     28:     trank = omp_get_thread_num();
     29:     icorr = tcomm->affinities[trank]%ncores;
     30:     CPU_SET(icorr,&mset);
     31:     sched_setaffinity(0,sizeof(cpu_set_t),&mset);
     32: #endif
     33:   }
     34:   return(0);
     35: }

     39: PetscErrorCode PetscThreadCommRunKernel_OpenMP(PetscThreadComm tcomm,PetscThreadCommJobCtx job)
     40: {
     41:   PetscInt        trank=0;

     44: #pragma omp parallel num_threads(tcomm->nworkThreads) shared(job) private(trank)
     45:   {
     46:     trank = omp_get_thread_num();
     47:     PetscRunKernel(trank,job->nargs,job);
     48:     job->job_status[trank] = THREAD_JOB_COMPLETED;
     49:   }
     50:   return(0);
     51: }