Actual source code: isltog.h


  2: /*
  3:      This is a terrible way of doing "templates" in C.
  4: */
  5: #define PETSCMAP1_a(a,b)  a ## b
  6: #define PETSCMAP1_b(a,b)  PETSCMAP1_a(a,b)
  7: #define PETSCMAPNAME(a)   PETSCMAP1_b(a,GTOLNAME)
  8: #define PETSCMAPTYPE(a)   PETSCMAP1_b(a,GTOLTYPE)

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

 19:   if (!map) {
 20:     ISGlobalToLocalMappingSetUp(mapping);
 21:     map  = (PETSCMAPTYPE(ISLocalToGlobalMapping) *)mapping->data;
 22:   }
 23:   start = mapping->globalstart;
 24:   end   = mapping->globalend;
 25:   bs    = GTOLBS;

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

 62: #undef PETSCMAP1_a
 63: #undef PETSCMAP1_b
 64: #undef PETSCMAPTYPE
 65: #undef PETSCMAPNAME
 66: #undef GTOLTYPE
 67: #undef GTOLNAME
 68: #undef GTOLBS
 69: #undef GTOL