Actual source code: isltog.h

  1: /*
  2:      This is a terrible way of doing "templates" in C.
  3: */
  4: #define PETSCMAPNAME(a) PetscConcat(a, GTOLNAME)
  5: #define PETSCMAPTYPE(a) PetscConcat(a, GTOLTYPE)

  7: static PetscErrorCode PETSCMAPNAME(ISGlobalToLocalMappingApply)(ISLocalToGlobalMapping mapping, ISGlobalToLocalMappingMode type, PetscInt n, const PetscInt idx[], PetscInt *nout, PetscInt idxout[])
  8: {
  9:   PetscInt i, nf = 0, tmp, start, end, bs;
 10:   PETSCMAPTYPE(ISLocalToGlobalMapping) *map = (PETSCMAPTYPE(ISLocalToGlobalMapping) *)mapping->data;

 12:   PetscFunctionBegin;
 14:   if (!map) {
 15:     PetscCall(ISGlobalToLocalMappingSetUp(mapping));
 16:     map = (PETSCMAPTYPE(ISLocalToGlobalMapping) *)mapping->data;
 17:   }
 18:   start = mapping->globalstart;
 19:   end   = mapping->globalend;
 20:   bs    = GTOLBS;

 22:   if (type == IS_GTOLM_MASK) {
 23:     if (idxout) {
 24:       for (i = 0; i < n; i++) {
 25:         if (idx[i] < 0) idxout[i] = idx[i];
 26:         else if (idx[i] < bs * start) idxout[i] = -1;
 27:         else if (idx[i] > bs * (end + 1) - 1) idxout[i] = -1;
 28:         else GTOL(idx[i], idxout[i]);
 29:       }
 30:     }
 31:     if (nout) *nout = n;
 32:   } else {
 33:     if (idxout) {
 34:       for (i = 0; i < n; i++) {
 35:         if (idx[i] < 0) continue;
 36:         if (idx[i] < bs * start) continue;
 37:         if (idx[i] > bs * (end + 1) - 1) continue;
 38:         GTOL(idx[i], tmp);
 39:         if (tmp < 0) continue;
 40:         idxout[nf++] = tmp;
 41:       }
 42:     } else {
 43:       for (i = 0; i < n; i++) {
 44:         if (idx[i] < 0) continue;
 45:         if (idx[i] < bs * start) continue;
 46:         if (idx[i] > bs * (end + 1) - 1) continue;
 47:         GTOL(idx[i], tmp);
 48:         if (tmp < 0) continue;
 49:         nf++;
 50:       }
 51:     }
 52:     if (nout) *nout = nf;
 53:   }
 54:   PetscFunctionReturn(PETSC_SUCCESS);
 55: }

 57: #undef PETSCMAPTYPE
 58: #undef PETSCMAPNAME
 59: #undef GTOLTYPE
 60: #undef GTOLNAME
 61: #undef GTOLBS
 62: #undef GTOL