1413f72f0SBarry Smith 2413f72f0SBarry Smith /* 3413f72f0SBarry Smith This is a terrible way of doing "templates" in C. 4413f72f0SBarry Smith */ 5413f72f0SBarry Smith #define PETSCMAP1_a(a,b) a ## b 6413f72f0SBarry Smith #define PETSCMAP1_b(a,b) PETSCMAP1_a(a,b) 7413f72f0SBarry Smith #define PETSCMAPNAME(a) PETSCMAP1_b(a,GTOLNAME) 8413f72f0SBarry Smith #define PETSCMAPTYPE(a) PETSCMAP1_b(a,GTOLTYPE) 9413f72f0SBarry Smith 10413f72f0SBarry Smith static PetscErrorCode PETSCMAPNAME(ISGlobalToLocalMappingApply)(ISLocalToGlobalMapping mapping,ISGlobalToLocalMappingMode type, 11413f72f0SBarry Smith PetscInt n,const PetscInt idx[],PetscInt *nout,PetscInt idxout[]) 12413f72f0SBarry Smith { 13413f72f0SBarry Smith PetscInt i,nf = 0,tmp,start,end,bs; 14413f72f0SBarry Smith PETSCMAPTYPE(ISLocalToGlobalMapping) *map = (PETSCMAPTYPE(ISLocalToGlobalMapping)*)mapping->data; 15413f72f0SBarry Smith PetscErrorCode ierr; 16413f72f0SBarry Smith 17413f72f0SBarry Smith PetscFunctionBegin; 18413f72f0SBarry Smith PetscValidHeaderSpecific(mapping,IS_LTOGM_CLASSID,1); 19413f72f0SBarry Smith if (!map) { 20413f72f0SBarry Smith ierr = ISGlobalToLocalMappingSetUp(mapping);CHKERRQ(ierr); 21413f72f0SBarry Smith map = (PETSCMAPTYPE(ISLocalToGlobalMapping) *)mapping->data; 22413f72f0SBarry Smith } 23413f72f0SBarry Smith start = mapping->globalstart; 24413f72f0SBarry Smith end = mapping->globalend; 25*541bf97eSAdrian Croucher bs = GTOLBS; 26413f72f0SBarry Smith 27413f72f0SBarry Smith 28413f72f0SBarry Smith 29413f72f0SBarry Smith if (type == IS_GTOLM_MASK) { 30413f72f0SBarry Smith if (idxout) { 31413f72f0SBarry Smith for (i=0; i<n; i++) { 32413f72f0SBarry Smith if (idx[i] < 0) idxout[i] = idx[i]; 33*541bf97eSAdrian Croucher else if (idx[i] < bs*start) idxout[i] = -1; 34*541bf97eSAdrian Croucher else if (idx[i] > bs*(end+1)-1) idxout[i] = -1; 35413f72f0SBarry Smith else GTOL(idx[i], idxout[i]); 36413f72f0SBarry Smith } 37413f72f0SBarry Smith } 38413f72f0SBarry Smith if (nout) *nout = n; 39413f72f0SBarry Smith } else { 40413f72f0SBarry Smith if (idxout) { 41413f72f0SBarry Smith for (i=0; i<n; i++) { 42413f72f0SBarry Smith if (idx[i] < 0) continue; 43*541bf97eSAdrian Croucher if (idx[i] < bs*start) continue; 44*541bf97eSAdrian Croucher if (idx[i] > bs*(end+1)-1) continue; 45413f72f0SBarry Smith GTOL(idx[i], tmp); 46413f72f0SBarry Smith if (tmp < 0) continue; 47413f72f0SBarry Smith idxout[nf++] = tmp; 48413f72f0SBarry Smith } 49413f72f0SBarry Smith } else { 50413f72f0SBarry Smith for (i=0; i<n; i++) { 51413f72f0SBarry Smith if (idx[i] < 0) continue; 52*541bf97eSAdrian Croucher if (idx[i] < bs*start) continue; 53*541bf97eSAdrian Croucher if (idx[i] > bs*(end+1)-1) continue; 54413f72f0SBarry Smith GTOL(idx[i], tmp); 55413f72f0SBarry Smith if (tmp < 0) continue; 56413f72f0SBarry Smith nf++; 57413f72f0SBarry Smith } 58413f72f0SBarry Smith } 59413f72f0SBarry Smith if (nout) *nout = nf; 60413f72f0SBarry Smith } 61413f72f0SBarry Smith PetscFunctionReturn(0); 62413f72f0SBarry Smith } 63413f72f0SBarry Smith 64413f72f0SBarry Smith #undef PETSCMAP1_a 65413f72f0SBarry Smith #undef PETSCMAP1_b 66413f72f0SBarry Smith #undef PETSCMAPTYPE 67413f72f0SBarry Smith #undef PETSCMAPNAME 68413f72f0SBarry Smith #undef GTOLTYPE 69413f72f0SBarry Smith #undef GTOLNAME 70*541bf97eSAdrian Croucher #undef GTOLBS 71413f72f0SBarry Smith #undef GTOL 72