10c735eedSKris Buschelman #define PETSCVEC_DLL 22362add9SBarry Smith 35f5f199fSBarry Smith #include "petscvec.h" /*I "petscvec.h" I*/ 47c4f633dSBarry Smith #include "private/isimpl.h" /*I "petscis.h" I*/ 52362add9SBarry Smith 60700a824SBarry Smith PetscClassId PETSCVEC_DLLEXPORT IS_LTOGM_CLASSID; 78e58c17dSMatthew Knepley 84a2ae208SSatish Balay #undef __FUNCT__ 94a2ae208SSatish Balay #define __FUNCT__ "ISLocalToGlobalMappingGetSize" 103b9aefa3SBarry Smith /*@C 113b9aefa3SBarry Smith ISLocalToGlobalMappingGetSize - Gets the local size of a local to global mapping. 123b9aefa3SBarry Smith 133b9aefa3SBarry Smith Not Collective 143b9aefa3SBarry Smith 153b9aefa3SBarry Smith Input Parameter: 163b9aefa3SBarry Smith . ltog - local to global mapping 173b9aefa3SBarry Smith 183b9aefa3SBarry Smith Output Parameter: 193b9aefa3SBarry Smith . n - the number of entries in the local mapping 203b9aefa3SBarry Smith 213b9aefa3SBarry Smith Level: advanced 223b9aefa3SBarry Smith 23273d9f13SBarry Smith Concepts: mapping^local to global 243b9aefa3SBarry Smith 253b9aefa3SBarry Smith .seealso: ISLocalToGlobalMappingDestroy(), ISLocalToGlobalMappingCreate() 263b9aefa3SBarry Smith @*/ 270c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingGetSize(ISLocalToGlobalMapping mapping,PetscInt *n) 283b9aefa3SBarry Smith { 293b9aefa3SBarry Smith PetscFunctionBegin; 300700a824SBarry Smith PetscValidHeaderSpecific(mapping,IS_LTOGM_CLASSID,1); 314482741eSBarry Smith PetscValidIntPointer(n,2); 323b9aefa3SBarry Smith *n = mapping->n; 333b9aefa3SBarry Smith PetscFunctionReturn(0); 343b9aefa3SBarry Smith } 353b9aefa3SBarry Smith 364a2ae208SSatish Balay #undef __FUNCT__ 374a2ae208SSatish Balay #define __FUNCT__ "ISLocalToGlobalMappingView" 385a5d4f66SBarry Smith /*@C 395a5d4f66SBarry Smith ISLocalToGlobalMappingView - View a local to global mapping 405a5d4f66SBarry Smith 41b9cd556bSLois Curfman McInnes Not Collective 42b9cd556bSLois Curfman McInnes 435a5d4f66SBarry Smith Input Parameters: 443b9aefa3SBarry Smith + ltog - local to global mapping 453b9aefa3SBarry Smith - viewer - viewer 465a5d4f66SBarry Smith 47a997ad1aSLois Curfman McInnes Level: advanced 48a997ad1aSLois Curfman McInnes 49273d9f13SBarry Smith Concepts: mapping^local to global 505a5d4f66SBarry Smith 515a5d4f66SBarry Smith .seealso: ISLocalToGlobalMappingDestroy(), ISLocalToGlobalMappingCreate() 525a5d4f66SBarry Smith @*/ 530c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingView(ISLocalToGlobalMapping mapping,PetscViewer viewer) 545a5d4f66SBarry Smith { 5532dcc486SBarry Smith PetscInt i; 5632dcc486SBarry Smith PetscMPIInt rank; 57ace3abfcSBarry Smith PetscBool iascii; 586849ba73SBarry Smith PetscErrorCode ierr; 595a5d4f66SBarry Smith 605a5d4f66SBarry Smith PetscFunctionBegin; 610700a824SBarry Smith PetscValidHeaderSpecific(mapping,IS_LTOGM_CLASSID,1); 623050cee2SBarry Smith if (!viewer) { 637adad957SLisandro Dalcin ierr = PetscViewerASCIIGetStdout(((PetscObject)mapping)->comm,&viewer);CHKERRQ(ierr); 643050cee2SBarry Smith } 650700a824SBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 665a5d4f66SBarry Smith 677adad957SLisandro Dalcin ierr = MPI_Comm_rank(((PetscObject)mapping)->comm,&rank);CHKERRQ(ierr); 682692d6eeSBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 6932077d6dSBarry Smith if (iascii) { 705a5d4f66SBarry Smith for (i=0; i<mapping->n; i++) { 71b0a32e0cSBarry Smith ierr = PetscViewerASCIISynchronizedPrintf(viewer,"[%d] %d %d\n",rank,i,mapping->indices[i]);CHKERRQ(ierr); 726831982aSBarry Smith } 73b0a32e0cSBarry Smith ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); 746831982aSBarry Smith } else { 75e32f2f54SBarry Smith SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Viewer type %s not supported for ISLocalToGlobalMapping",((PetscObject)viewer)->type_name); 765a5d4f66SBarry Smith } 775a5d4f66SBarry Smith 785a5d4f66SBarry Smith PetscFunctionReturn(0); 795a5d4f66SBarry Smith } 805a5d4f66SBarry Smith 814a2ae208SSatish Balay #undef __FUNCT__ 824a2ae208SSatish Balay #define __FUNCT__ "ISLocalToGlobalMappingCreateIS" 831f428162SBarry Smith /*@ 842bdab257SBarry Smith ISLocalToGlobalMappingCreateIS - Creates a mapping between a local (0 to n) 852bdab257SBarry Smith ordering and a global parallel ordering. 862bdab257SBarry Smith 870f5bd95cSBarry Smith Not collective 88b9cd556bSLois Curfman McInnes 89a997ad1aSLois Curfman McInnes Input Parameter: 908c03b21aSDmitry Karpeev . is - index set containing the global numbers for each local number 912bdab257SBarry Smith 92a997ad1aSLois Curfman McInnes Output Parameter: 932bdab257SBarry Smith . mapping - new mapping data structure 942bdab257SBarry Smith 95a997ad1aSLois Curfman McInnes Level: advanced 96a997ad1aSLois Curfman McInnes 97273d9f13SBarry Smith Concepts: mapping^local to global 982bdab257SBarry Smith 992bdab257SBarry Smith .seealso: ISLocalToGlobalMappingDestroy(), ISLocalToGlobalMappingCreate() 1002bdab257SBarry Smith @*/ 1010c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingCreateIS(IS is,ISLocalToGlobalMapping *mapping) 1022bdab257SBarry Smith { 1036849ba73SBarry Smith PetscErrorCode ierr; 1045d0c19d7SBarry Smith PetscInt n; 1055d0c19d7SBarry Smith const PetscInt *indices; 1062bdab257SBarry Smith MPI_Comm comm; 1073a40ed3dSBarry Smith 1083a40ed3dSBarry Smith PetscFunctionBegin; 1090700a824SBarry Smith PetscValidHeaderSpecific(is,IS_CLASSID,1); 1104482741eSBarry Smith PetscValidPointer(mapping,2); 1112bdab257SBarry Smith 1122bdab257SBarry Smith ierr = PetscObjectGetComm((PetscObject)is,&comm);CHKERRQ(ierr); 1133b9aefa3SBarry Smith ierr = ISGetLocalSize(is,&n);CHKERRQ(ierr); 1142bdab257SBarry Smith ierr = ISGetIndices(is,&indices);CHKERRQ(ierr); 115d5ad8652SBarry Smith ierr = ISLocalToGlobalMappingCreate(comm,n,indices,PETSC_COPY_VALUES,mapping);CHKERRQ(ierr); 1162bdab257SBarry Smith ierr = ISRestoreIndices(is,&indices);CHKERRQ(ierr); 1173a40ed3dSBarry Smith PetscFunctionReturn(0); 1182bdab257SBarry Smith } 1195a5d4f66SBarry Smith 120b46b645bSBarry Smith 1214a2ae208SSatish Balay #undef __FUNCT__ 1224a2ae208SSatish Balay #define __FUNCT__ "ISLocalToGlobalMappingCreate" 123ba5bb76aSSatish Balay /*@ 12490f02eecSBarry Smith ISLocalToGlobalMappingCreate - Creates a mapping between a local (0 to n) 12590f02eecSBarry Smith ordering and a global parallel ordering. 1262362add9SBarry Smith 12789d82c54SBarry Smith Not Collective, but communicator may have more than one process 128b9cd556bSLois Curfman McInnes 1292362add9SBarry Smith Input Parameters: 13089d82c54SBarry Smith + comm - MPI communicator 13190f02eecSBarry Smith . n - the number of local elements 132d5ad8652SBarry Smith . indices - the global index for each local element 133d5ad8652SBarry Smith - mode - see PetscCopyMode 1342362add9SBarry Smith 135a997ad1aSLois Curfman McInnes Output Parameter: 13690f02eecSBarry Smith . mapping - new mapping data structure 1372362add9SBarry Smith 138a997ad1aSLois Curfman McInnes Level: advanced 139a997ad1aSLois Curfman McInnes 140273d9f13SBarry Smith Concepts: mapping^local to global 1412362add9SBarry Smith 142d5ad8652SBarry Smith .seealso: ISLocalToGlobalMappingDestroy(), ISLocalToGlobalMappingCreateIS() 1432362add9SBarry Smith @*/ 144d5ad8652SBarry Smith PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingCreate(MPI_Comm cm,PetscInt n,const PetscInt indices[],PetscCopyMode mode,ISLocalToGlobalMapping *mapping) 1452362add9SBarry Smith { 1466849ba73SBarry Smith PetscErrorCode ierr; 14732dcc486SBarry Smith PetscInt *in; 148b46b645bSBarry Smith 149b46b645bSBarry Smith PetscFunctionBegin; 15073911063SBarry Smith if (n) PetscValidIntPointer(indices,3); 1514482741eSBarry Smith PetscValidPointer(mapping,4); 152b46b645bSBarry Smith 1538e58c17dSMatthew Knepley *mapping = PETSC_NULL; 1548e58c17dSMatthew Knepley #ifndef PETSC_USE_DYNAMIC_LIBRARIES 1552b6de112SBarry Smith ierr = ISInitializePackage(PETSC_NULL);CHKERRQ(ierr); 1568e58c17dSMatthew Knepley #endif 1572362add9SBarry Smith 1580700a824SBarry Smith ierr = PetscHeaderCreate(*mapping,_p_ISLocalToGlobalMapping,int,IS_LTOGM_CLASSID,0,"ISLocalToGlobalMapping", 15952e6d16bSBarry Smith cm,ISLocalToGlobalMappingDestroy,ISLocalToGlobalMappingView);CHKERRQ(ierr); 160d4bb536fSBarry Smith (*mapping)->n = n; 161d4bb536fSBarry Smith /* 162d4bb536fSBarry Smith Do not create the global to local mapping. This is only created if 163d4bb536fSBarry Smith ISGlobalToLocalMapping() is called 164d4bb536fSBarry Smith */ 165d4bb536fSBarry Smith (*mapping)->globals = 0; 166d5ad8652SBarry Smith if (mode == PETSC_COPY_VALUES) { 167d5ad8652SBarry Smith ierr = PetscMalloc(n*sizeof(PetscInt),&in);CHKERRQ(ierr); 168d5ad8652SBarry Smith ierr = PetscMemcpy(in,indices,n*sizeof(PetscInt));CHKERRQ(ierr); 169d5ad8652SBarry Smith ierr = PetscLogObjectMemory(*mapping,n*sizeof(PetscInt));CHKERRQ(ierr); 170d5ad8652SBarry Smith (*mapping)->indices = in; 171d5ad8652SBarry Smith } else if (mode == PETSC_OWN_POINTER) { 172d5ad8652SBarry Smith (*mapping)->indices = (PetscInt*)indices; 173d5ad8652SBarry Smith } else SETERRQ(cm,PETSC_ERR_SUP,"Cannot currently use PETSC_USE_POINTER"); 1743a40ed3dSBarry Smith PetscFunctionReturn(0); 1752362add9SBarry Smith } 1762362add9SBarry Smith 1774a2ae208SSatish Balay #undef __FUNCT__ 1784a2ae208SSatish Balay #define __FUNCT__ "ISLocalToGlobalMappingBlock" 179bce096a4SSatish Balay /*@ 180323b833fSBarry Smith ISLocalToGlobalMappingBlock - Creates a blocked index version of an 181323b833fSBarry Smith ISLocalToGlobalMapping that is appropriate for MatSetLocalToGlobalMappingBlock() 182323b833fSBarry Smith and VecSetLocalToGlobalMappingBlock(). 183323b833fSBarry Smith 184323b833fSBarry Smith Not Collective, but communicator may have more than one process 185323b833fSBarry Smith 186323b833fSBarry Smith Input Parameters: 187323b833fSBarry Smith + inmap - original point-wise mapping 188323b833fSBarry Smith - bs - block size 189323b833fSBarry Smith 190323b833fSBarry Smith Output Parameter: 19169eb54c3SBarry Smith . outmap - block based mapping; the indices are relative to BLOCKS, not individual vector or matrix entries. 192323b833fSBarry Smith 193323b833fSBarry Smith Level: advanced 194323b833fSBarry Smith 195323b833fSBarry Smith Concepts: mapping^local to global 196323b833fSBarry Smith 197323b833fSBarry Smith .seealso: ISLocalToGlobalMappingDestroy(), ISLocalToGlobalMappingCreate(), ISLocalToGlobalMappingCreateIS() 198323b833fSBarry Smith @*/ 1990c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingBlock(ISLocalToGlobalMapping inmap,PetscInt bs,ISLocalToGlobalMapping *outmap) 200323b833fSBarry Smith { 2016849ba73SBarry Smith PetscErrorCode ierr; 20232dcc486SBarry Smith PetscInt *ii,i,n; 203323b833fSBarry Smith 204323b833fSBarry Smith PetscFunctionBegin; 2050700a824SBarry Smith PetscValidHeaderSpecific(inmap,IS_LTOGM_CLASSID,1); 206b2beed0aSJed Brown PetscValidPointer(outmap,3); 207323b833fSBarry Smith if (bs > 1) { 208323b833fSBarry Smith n = inmap->n/bs; 209e32f2f54SBarry Smith if (n*bs != inmap->n) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_INCOMP,"Pointwise mapping length is not divisible by block size"); 21032dcc486SBarry Smith ierr = PetscMalloc(n*sizeof(PetscInt),&ii);CHKERRQ(ierr); 211323b833fSBarry Smith for (i=0; i<n; i++) { 212db032c9dSBarry Smith ii[i] = inmap->indices[bs*i]/bs; 213323b833fSBarry Smith } 214d5ad8652SBarry Smith ierr = ISLocalToGlobalMappingCreate(((PetscObject)inmap)->comm,n,ii,PETSC_OWN_POINTER,outmap);CHKERRQ(ierr); 215323b833fSBarry Smith } else { 216323b833fSBarry Smith ierr = PetscObjectReference((PetscObject)inmap);CHKERRQ(ierr); 217c3122656SLisandro Dalcin *outmap = inmap; 218323b833fSBarry Smith } 219323b833fSBarry Smith PetscFunctionReturn(0); 220323b833fSBarry Smith } 221323b833fSBarry Smith 2224a2ae208SSatish Balay #undef __FUNCT__ 223*8ab951edSJed Brown #define __FUNCT__ "ISLocalToGlobalMappingUnBlock" 224b2beed0aSJed Brown /*@ 225b2beed0aSJed Brown ISLocalToGlobalMappingUnBlock - Creates a scalar index version of a blocked 226b2beed0aSJed Brown ISLocalToGlobalMapping 227b2beed0aSJed Brown 228b2beed0aSJed Brown Not Collective, but communicator may have more than one process 229b2beed0aSJed Brown 230b2beed0aSJed Brown Input Parameter: 231b2beed0aSJed Brown +inmap - block based mapping; the indices are relative to BLOCKS, not individual vector or matrix entries. 232b2beed0aSJed Brown -bs - block size 233b2beed0aSJed Brown 234b2beed0aSJed Brown Output Parameter: 235b2beed0aSJed Brown . outmap - pointwise mapping 236b2beed0aSJed Brown 237b2beed0aSJed Brown Level: advanced 238b2beed0aSJed Brown 239b2beed0aSJed Brown Concepts: mapping^local to global 240b2beed0aSJed Brown 241b2beed0aSJed Brown .seealso: ISLocalToGlobalMappingDestroy(), ISLocalToGlobalMappingCreate(), ISLocalToGlobalMappingBlock() 242b2beed0aSJed Brown @*/ 243b2beed0aSJed Brown PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingUnBlock(ISLocalToGlobalMapping inmap,PetscInt bs,ISLocalToGlobalMapping *outmap) 244b2beed0aSJed Brown { 245b2beed0aSJed Brown PetscErrorCode ierr; 246b2beed0aSJed Brown PetscInt *ii,i,n; 247b2beed0aSJed Brown 248b2beed0aSJed Brown PetscFunctionBegin; 249b2beed0aSJed Brown PetscValidHeaderSpecific(inmap,IS_LTOGM_CLASSID,1); 250b2beed0aSJed Brown PetscValidPointer(outmap,2); 251b2beed0aSJed Brown if (bs > 1) { 252b2beed0aSJed Brown n = inmap->n*bs; 253b2beed0aSJed Brown ierr = PetscMalloc(n*sizeof(PetscInt),&ii);CHKERRQ(ierr); 254b2beed0aSJed Brown for (i=0; i<n; i++) { 255b2beed0aSJed Brown ii[i] = inmap->indices[i%bs]*bs; 256b2beed0aSJed Brown } 257b2beed0aSJed Brown ierr = ISLocalToGlobalMappingCreate(((PetscObject)inmap)->comm,n,ii,PETSC_OWN_POINTER,outmap);CHKERRQ(ierr); 258b2beed0aSJed Brown } else { 259b2beed0aSJed Brown ierr = PetscObjectReference((PetscObject)inmap);CHKERRQ(ierr); 260b2beed0aSJed Brown *outmap = inmap; 261b2beed0aSJed Brown } 262b2beed0aSJed Brown PetscFunctionReturn(0); 263b2beed0aSJed Brown } 264b2beed0aSJed Brown 265b2beed0aSJed Brown #undef __FUNCT__ 2664a2ae208SSatish Balay #define __FUNCT__ "ISLocalToGlobalMappingDestroy" 26790f02eecSBarry Smith /*@ 26890f02eecSBarry Smith ISLocalToGlobalMappingDestroy - Destroys a mapping between a local (0 to n) 26990f02eecSBarry Smith ordering and a global parallel ordering. 27090f02eecSBarry Smith 2710f5bd95cSBarry Smith Note Collective 272b9cd556bSLois Curfman McInnes 27390f02eecSBarry Smith Input Parameters: 27490f02eecSBarry Smith . mapping - mapping data structure 27590f02eecSBarry Smith 276a997ad1aSLois Curfman McInnes Level: advanced 277a997ad1aSLois Curfman McInnes 2783acfe500SLois Curfman McInnes .seealso: ISLocalToGlobalMappingCreate() 27990f02eecSBarry Smith @*/ 2800c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping mapping) 28190f02eecSBarry Smith { 282dfbe8321SBarry Smith PetscErrorCode ierr; 2833a40ed3dSBarry Smith PetscFunctionBegin; 2840700a824SBarry Smith PetscValidHeaderSpecific(mapping,IS_LTOGM_CLASSID,1); 2857adad957SLisandro Dalcin if (--((PetscObject)mapping)->refct > 0) PetscFunctionReturn(0); 286606d414cSSatish Balay ierr = PetscFree(mapping->indices);CHKERRQ(ierr); 28705b42c5fSBarry Smith ierr = PetscFree(mapping->globals);CHKERRQ(ierr); 288d38fa0fbSBarry Smith ierr = PetscHeaderDestroy(mapping);CHKERRQ(ierr); 2893a40ed3dSBarry Smith PetscFunctionReturn(0); 29090f02eecSBarry Smith } 29190f02eecSBarry Smith 2924a2ae208SSatish Balay #undef __FUNCT__ 2934a2ae208SSatish Balay #define __FUNCT__ "ISLocalToGlobalMappingApplyIS" 29490f02eecSBarry Smith /*@ 2953acfe500SLois Curfman McInnes ISLocalToGlobalMappingApplyIS - Creates from an IS in the local numbering 2963acfe500SLois Curfman McInnes a new index set using the global numbering defined in an ISLocalToGlobalMapping 2973acfe500SLois Curfman McInnes context. 29890f02eecSBarry Smith 299b9cd556bSLois Curfman McInnes Not collective 300b9cd556bSLois Curfman McInnes 30190f02eecSBarry Smith Input Parameters: 302b9cd556bSLois Curfman McInnes + mapping - mapping between local and global numbering 303b9cd556bSLois Curfman McInnes - is - index set in local numbering 30490f02eecSBarry Smith 30590f02eecSBarry Smith Output Parameters: 30690f02eecSBarry Smith . newis - index set in global numbering 30790f02eecSBarry Smith 308a997ad1aSLois Curfman McInnes Level: advanced 309a997ad1aSLois Curfman McInnes 310273d9f13SBarry Smith Concepts: mapping^local to global 3113acfe500SLois Curfman McInnes 31290f02eecSBarry Smith .seealso: ISLocalToGlobalMappingApply(), ISLocalToGlobalMappingCreate(), 313d4bb536fSBarry Smith ISLocalToGlobalMappingDestroy(), ISGlobalToLocalMappingApply() 31490f02eecSBarry Smith @*/ 3150c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping mapping,IS is,IS *newis) 31690f02eecSBarry Smith { 3176849ba73SBarry Smith PetscErrorCode ierr; 3185d0c19d7SBarry Smith PetscInt n,i,*idxmap,*idxout,Nmax = mapping->n; 3195d0c19d7SBarry Smith const PetscInt *idxin; 3203a40ed3dSBarry Smith 3213a40ed3dSBarry Smith PetscFunctionBegin; 3220700a824SBarry Smith PetscValidHeaderSpecific(mapping,IS_LTOGM_CLASSID,1); 3230700a824SBarry Smith PetscValidHeaderSpecific(is,IS_CLASSID,2); 3244482741eSBarry Smith PetscValidPointer(newis,3); 32590f02eecSBarry Smith 3263b9aefa3SBarry Smith ierr = ISGetLocalSize(is,&n);CHKERRQ(ierr); 32790f02eecSBarry Smith ierr = ISGetIndices(is,&idxin);CHKERRQ(ierr); 32890f02eecSBarry Smith idxmap = mapping->indices; 32990f02eecSBarry Smith 3307c334f02SBarry Smith ierr = PetscMalloc(n*sizeof(PetscInt),&idxout);CHKERRQ(ierr); 33190f02eecSBarry Smith for (i=0; i<n; i++) { 332e32f2f54SBarry Smith if (idxin[i] >= Nmax) SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Local index %d too large %d (max) at %d",idxin[i],Nmax-1,i); 33390f02eecSBarry Smith idxout[i] = idxmap[idxin[i]]; 33490f02eecSBarry Smith } 3353b9aefa3SBarry Smith ierr = ISRestoreIndices(is,&idxin);CHKERRQ(ierr); 33670b3c8c7SBarry Smith ierr = ISCreateGeneral(PETSC_COMM_SELF,n,idxout,PETSC_OWN_POINTER,newis);CHKERRQ(ierr); 3373a40ed3dSBarry Smith PetscFunctionReturn(0); 33890f02eecSBarry Smith } 33990f02eecSBarry Smith 34089d82c54SBarry Smith /*MC 3413acfe500SLois Curfman McInnes ISLocalToGlobalMappingApply - Takes a list of integers in a local numbering 3423acfe500SLois Curfman McInnes and converts them to the global numbering. 34390f02eecSBarry Smith 344eca87e8dSBarry Smith Synopsis: 345eca87e8dSBarry Smith PetscErrorCode ISLocalToGlobalMappingApply(ISLocalToGlobalMapping mapping,int N,int in[],int out[]) 346eca87e8dSBarry Smith 347b9cd556bSLois Curfman McInnes Not collective 348b9cd556bSLois Curfman McInnes 349bb25748dSBarry Smith Input Parameters: 350b9cd556bSLois Curfman McInnes + mapping - the local to global mapping context 351bb25748dSBarry Smith . N - number of integers 352b9cd556bSLois Curfman McInnes - in - input indices in local numbering 353bb25748dSBarry Smith 354bb25748dSBarry Smith Output Parameter: 355bb25748dSBarry Smith . out - indices in global numbering 356bb25748dSBarry Smith 357b9cd556bSLois Curfman McInnes Notes: 358b9cd556bSLois Curfman McInnes The in and out array parameters may be identical. 359d4bb536fSBarry Smith 360a997ad1aSLois Curfman McInnes Level: advanced 361a997ad1aSLois Curfman McInnes 362bb25748dSBarry Smith .seealso: ISLocalToGlobalMappingCreate(),ISLocalToGlobalMappingDestroy(), 3630752156aSBarry Smith ISLocalToGlobalMappingApplyIS(),AOCreateBasic(),AOApplicationToPetsc(), 364d4bb536fSBarry Smith AOPetscToApplication(), ISGlobalToLocalMappingApply() 365bb25748dSBarry Smith 366273d9f13SBarry Smith Concepts: mapping^local to global 367d4bb536fSBarry Smith 36889d82c54SBarry Smith M*/ 369d4bb536fSBarry Smith 370d4bb536fSBarry Smith /* -----------------------------------------------------------------------------------------*/ 371d4bb536fSBarry Smith 3724a2ae208SSatish Balay #undef __FUNCT__ 3734a2ae208SSatish Balay #define __FUNCT__ "ISGlobalToLocalMappingSetUp_Private" 374d4bb536fSBarry Smith /* 375d4bb536fSBarry Smith Creates the global fields in the ISLocalToGlobalMapping structure 376d4bb536fSBarry Smith */ 3776849ba73SBarry Smith static PetscErrorCode ISGlobalToLocalMappingSetUp_Private(ISLocalToGlobalMapping mapping) 378d4bb536fSBarry Smith { 3796849ba73SBarry Smith PetscErrorCode ierr; 38032dcc486SBarry Smith PetscInt i,*idx = mapping->indices,n = mapping->n,end,start,*globals; 381d4bb536fSBarry Smith 3823a40ed3dSBarry Smith PetscFunctionBegin; 383d4bb536fSBarry Smith end = 0; 384d4bb536fSBarry Smith start = 100000000; 385d4bb536fSBarry Smith 386d4bb536fSBarry Smith for (i=0; i<n; i++) { 387d4bb536fSBarry Smith if (idx[i] < 0) continue; 388d4bb536fSBarry Smith if (idx[i] < start) start = idx[i]; 389d4bb536fSBarry Smith if (idx[i] > end) end = idx[i]; 390d4bb536fSBarry Smith } 391d4bb536fSBarry Smith if (start > end) {start = 0; end = -1;} 392d4bb536fSBarry Smith mapping->globalstart = start; 393d4bb536fSBarry Smith mapping->globalend = end; 394d4bb536fSBarry Smith 39532dcc486SBarry Smith ierr = PetscMalloc((end-start+2)*sizeof(PetscInt),&globals);CHKERRQ(ierr); 396b0a32e0cSBarry Smith mapping->globals = globals; 397d4bb536fSBarry Smith for (i=0; i<end-start+1; i++) { 398d4bb536fSBarry Smith globals[i] = -1; 399d4bb536fSBarry Smith } 400d4bb536fSBarry Smith for (i=0; i<n; i++) { 401d4bb536fSBarry Smith if (idx[i] < 0) continue; 402d4bb536fSBarry Smith globals[idx[i] - start] = i; 403d4bb536fSBarry Smith } 404d4bb536fSBarry Smith 40552e6d16bSBarry Smith ierr = PetscLogObjectMemory(mapping,(end-start+1)*sizeof(PetscInt));CHKERRQ(ierr); 4063a40ed3dSBarry Smith PetscFunctionReturn(0); 407d4bb536fSBarry Smith } 408d4bb536fSBarry Smith 4094a2ae208SSatish Balay #undef __FUNCT__ 4104a2ae208SSatish Balay #define __FUNCT__ "ISGlobalToLocalMappingApply" 411d4bb536fSBarry Smith /*@ 412a997ad1aSLois Curfman McInnes ISGlobalToLocalMappingApply - Provides the local numbering for a list of integers 413a997ad1aSLois Curfman McInnes specified with a global numbering. 414d4bb536fSBarry Smith 415b9cd556bSLois Curfman McInnes Not collective 416b9cd556bSLois Curfman McInnes 417d4bb536fSBarry Smith Input Parameters: 418b9cd556bSLois Curfman McInnes + mapping - mapping between local and global numbering 419d4bb536fSBarry Smith . type - IS_GTOLM_MASK - replaces global indices with no local value with -1 420d4bb536fSBarry Smith IS_GTOLM_DROP - drops the indices with no local value from the output list 421d4bb536fSBarry Smith . n - number of global indices to map 422b9cd556bSLois Curfman McInnes - idx - global indices to map 423d4bb536fSBarry Smith 424d4bb536fSBarry Smith Output Parameters: 425b9cd556bSLois Curfman McInnes + nout - number of indices in output array (if type == IS_GTOLM_MASK then nout = n) 426b9cd556bSLois Curfman McInnes - idxout - local index of each global index, one must pass in an array long enough 427e182c471SBarry Smith to hold all the indices. You can call ISGlobalToLocalMappingApply() with 428e182c471SBarry Smith idxout == PETSC_NULL to determine the required length (returned in nout) 429e182c471SBarry Smith and then allocate the required space and call ISGlobalToLocalMappingApply() 430e182c471SBarry Smith a second time to set the values. 431d4bb536fSBarry Smith 432b9cd556bSLois Curfman McInnes Notes: 433b9cd556bSLois Curfman McInnes Either nout or idxout may be PETSC_NULL. idx and idxout may be identical. 434d4bb536fSBarry Smith 4350f5bd95cSBarry Smith This is not scalable in memory usage. Each processor requires O(Nglobal) size 4360f5bd95cSBarry Smith array to compute these. 4370f5bd95cSBarry Smith 438a997ad1aSLois Curfman McInnes Level: advanced 439a997ad1aSLois Curfman McInnes 440273d9f13SBarry Smith Concepts: mapping^global to local 441d4bb536fSBarry Smith 442d4bb536fSBarry Smith .seealso: ISLocalToGlobalMappingApply(), ISLocalToGlobalMappingCreate(), 443d4bb536fSBarry Smith ISLocalToGlobalMappingDestroy() 444d4bb536fSBarry Smith @*/ 4450c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT ISGlobalToLocalMappingApply(ISLocalToGlobalMapping mapping,ISGlobalToLocalMappingType type, 44632dcc486SBarry Smith PetscInt n,const PetscInt idx[],PetscInt *nout,PetscInt idxout[]) 447d4bb536fSBarry Smith { 44832dcc486SBarry Smith PetscInt i,*globals,nf = 0,tmp,start,end; 4496849ba73SBarry Smith PetscErrorCode ierr; 450d4bb536fSBarry Smith 4513a40ed3dSBarry Smith PetscFunctionBegin; 4520700a824SBarry Smith PetscValidHeaderSpecific(mapping,IS_LTOGM_CLASSID,1); 453d4bb536fSBarry Smith if (!mapping->globals) { 454d4bb536fSBarry Smith ierr = ISGlobalToLocalMappingSetUp_Private(mapping);CHKERRQ(ierr); 455d4bb536fSBarry Smith } 456d4bb536fSBarry Smith globals = mapping->globals; 457d4bb536fSBarry Smith start = mapping->globalstart; 458d4bb536fSBarry Smith end = mapping->globalend; 459d4bb536fSBarry Smith 460d4bb536fSBarry Smith if (type == IS_GTOLM_MASK) { 461d4bb536fSBarry Smith if (idxout) { 462d4bb536fSBarry Smith for (i=0; i<n; i++) { 463d4bb536fSBarry Smith if (idx[i] < 0) idxout[i] = idx[i]; 464d4bb536fSBarry Smith else if (idx[i] < start) idxout[i] = -1; 465d4bb536fSBarry Smith else if (idx[i] > end) idxout[i] = -1; 466d4bb536fSBarry Smith else idxout[i] = globals[idx[i] - start]; 467d4bb536fSBarry Smith } 468d4bb536fSBarry Smith } 469d4bb536fSBarry Smith if (nout) *nout = n; 470d4bb536fSBarry Smith } else { 471d4bb536fSBarry Smith if (idxout) { 472d4bb536fSBarry Smith for (i=0; i<n; i++) { 473d4bb536fSBarry Smith if (idx[i] < 0) continue; 474d4bb536fSBarry Smith if (idx[i] < start) continue; 475d4bb536fSBarry Smith if (idx[i] > end) continue; 476d4bb536fSBarry Smith tmp = globals[idx[i] - start]; 477d4bb536fSBarry Smith if (tmp < 0) continue; 478d4bb536fSBarry Smith idxout[nf++] = tmp; 479d4bb536fSBarry Smith } 480d4bb536fSBarry Smith } else { 481d4bb536fSBarry Smith for (i=0; i<n; i++) { 482d4bb536fSBarry Smith if (idx[i] < 0) continue; 483d4bb536fSBarry Smith if (idx[i] < start) continue; 484d4bb536fSBarry Smith if (idx[i] > end) continue; 485d4bb536fSBarry Smith tmp = globals[idx[i] - start]; 486d4bb536fSBarry Smith if (tmp < 0) continue; 487d4bb536fSBarry Smith nf++; 488d4bb536fSBarry Smith } 489d4bb536fSBarry Smith } 490d4bb536fSBarry Smith if (nout) *nout = nf; 491d4bb536fSBarry Smith } 492d4bb536fSBarry Smith 4933a40ed3dSBarry Smith PetscFunctionReturn(0); 494d4bb536fSBarry Smith } 49590f02eecSBarry Smith 4964a2ae208SSatish Balay #undef __FUNCT__ 4974a2ae208SSatish Balay #define __FUNCT__ "ISLocalToGlobalMappingGetInfo" 49889d82c54SBarry Smith /*@C 49989d82c54SBarry Smith ISLocalToGlobalMappingGetInfo - Gets the neighbor information for each processor and 50089d82c54SBarry Smith each index shared by more than one processor 50189d82c54SBarry Smith 50289d82c54SBarry Smith Collective on ISLocalToGlobalMapping 50389d82c54SBarry Smith 50489d82c54SBarry Smith Input Parameters: 50589d82c54SBarry Smith . mapping - the mapping from local to global indexing 50689d82c54SBarry Smith 50789d82c54SBarry Smith Output Parameter: 50889d82c54SBarry Smith + nproc - number of processors that are connected to this one 50989d82c54SBarry Smith . proc - neighboring processors 51007b52d57SBarry Smith . numproc - number of indices for each subdomain (processor) 5113463a7baSJed Brown - indices - indices of nodes (in local numbering) shared with neighbors (sorted by global numbering) 51289d82c54SBarry Smith 51389d82c54SBarry Smith Level: advanced 51489d82c54SBarry Smith 515273d9f13SBarry Smith Concepts: mapping^local to global 51689d82c54SBarry Smith 5172cfcea29SBarry Smith Fortran Usage: 5182cfcea29SBarry Smith $ ISLocalToGlobalMpngGetInfoSize(ISLocalToGlobalMapping,PetscInt nproc,PetscInt numprocmax,ierr) followed by 5192cfcea29SBarry Smith $ ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping,PetscInt nproc, PetscInt procs[nproc],PetscInt numprocs[nproc], 5202cfcea29SBarry Smith PetscInt indices[nproc][numprocmax],ierr) 5212cfcea29SBarry Smith There is no ISLocalToGlobalMappingRestoreInfo() in Fortran. You must make sure that procs[], numprocs[] and 5222cfcea29SBarry Smith indices[][] are large enough arrays, either by allocating them dynamically or defining static ones large enough. 5232cfcea29SBarry Smith 5242cfcea29SBarry Smith 52507b52d57SBarry Smith .seealso: ISLocalToGlobalMappingDestroy(), ISLocalToGlobalMappingCreateIS(), ISLocalToGlobalMappingCreate(), 52607b52d57SBarry Smith ISLocalToGlobalMappingRestoreInfo() 52789d82c54SBarry Smith @*/ 5280c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping mapping,PetscInt *nproc,PetscInt *procs[],PetscInt *numprocs[],PetscInt **indices[]) 52989d82c54SBarry Smith { 5306849ba73SBarry Smith PetscErrorCode ierr; 53197f1f81fSBarry Smith PetscMPIInt size,rank,tag1,tag2,tag3,*len,*source,imdex; 53232dcc486SBarry Smith PetscInt i,n = mapping->n,Ng,ng,max = 0,*lindices = mapping->indices; 53332dcc486SBarry Smith PetscInt *nprocs,*owner,nsends,*sends,j,*starts,nmax,nrecvs,*recvs,proc; 53497f1f81fSBarry Smith PetscInt cnt,scale,*ownedsenders,*nownedsenders,rstart,nowned; 53532dcc486SBarry Smith PetscInt node,nownedm,nt,*sends2,nsends2,*starts2,*lens2,*dest,nrecvs2,*starts3,*recvs2,k,*bprocs,*tmp; 53632dcc486SBarry Smith PetscInt first_procs,first_numprocs,*first_indices; 53789d82c54SBarry Smith MPI_Request *recv_waits,*send_waits; 53830dcb7c9SBarry Smith MPI_Status recv_status,*send_status,*recv_statuses; 5397adad957SLisandro Dalcin MPI_Comm comm = ((PetscObject)mapping)->comm; 540ace3abfcSBarry Smith PetscBool debug = PETSC_FALSE; 54189d82c54SBarry Smith 54289d82c54SBarry Smith PetscFunctionBegin; 5430700a824SBarry Smith PetscValidHeaderSpecific(mapping,IS_LTOGM_CLASSID,1); 54424cf384cSBarry Smith ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr); 54524cf384cSBarry Smith ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); 54624cf384cSBarry Smith if (size == 1) { 54724cf384cSBarry Smith *nproc = 0; 54824cf384cSBarry Smith *procs = PETSC_NULL; 54932dcc486SBarry Smith ierr = PetscMalloc(sizeof(PetscInt),numprocs);CHKERRQ(ierr); 5501e2105dcSBarry Smith (*numprocs)[0] = 0; 55132dcc486SBarry Smith ierr = PetscMalloc(sizeof(PetscInt*),indices);CHKERRQ(ierr); 5521e2105dcSBarry Smith (*indices)[0] = PETSC_NULL; 55324cf384cSBarry Smith PetscFunctionReturn(0); 55424cf384cSBarry Smith } 55524cf384cSBarry Smith 556acfcf0e5SJed Brown ierr = PetscOptionsGetBool(PETSC_NULL,"-islocaltoglobalmappinggetinfo_debug",&debug,PETSC_NULL);CHKERRQ(ierr); 55707b52d57SBarry Smith 5583677ff5aSBarry Smith /* 5593677ff5aSBarry Smith Notes on ISLocalToGlobalMappingGetInfo 5603677ff5aSBarry Smith 5613677ff5aSBarry Smith globally owned node - the nodes that have been assigned to this processor in global 5623677ff5aSBarry Smith numbering, just for this routine. 5633677ff5aSBarry Smith 5643677ff5aSBarry Smith nontrivial globally owned node - node assigned to this processor that is on a subdomain 5653677ff5aSBarry Smith boundary (i.e. is has more than one local owner) 5663677ff5aSBarry Smith 5673677ff5aSBarry Smith locally owned node - node that exists on this processors subdomain 5683677ff5aSBarry Smith 5693677ff5aSBarry Smith nontrivial locally owned node - node that is not in the interior (i.e. has more than one 5703677ff5aSBarry Smith local subdomain 5713677ff5aSBarry Smith */ 57224cf384cSBarry Smith ierr = PetscObjectGetNewTag((PetscObject)mapping,&tag1);CHKERRQ(ierr); 57324cf384cSBarry Smith ierr = PetscObjectGetNewTag((PetscObject)mapping,&tag2);CHKERRQ(ierr); 57424cf384cSBarry Smith ierr = PetscObjectGetNewTag((PetscObject)mapping,&tag3);CHKERRQ(ierr); 57589d82c54SBarry Smith 57689d82c54SBarry Smith for (i=0; i<n; i++) { 57789d82c54SBarry Smith if (lindices[i] > max) max = lindices[i]; 57889d82c54SBarry Smith } 57932dcc486SBarry Smith ierr = MPI_Allreduce(&max,&Ng,1,MPIU_INT,MPI_MAX,comm);CHKERRQ(ierr); 58078058e43SBarry Smith Ng++; 58189d82c54SBarry Smith ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr); 58289d82c54SBarry Smith ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); 583bc8ff85bSBarry Smith scale = Ng/size + 1; 584a2e34c3dSBarry Smith ng = scale; if (rank == size-1) ng = Ng - scale*(size-1); ng = PetscMax(1,ng); 585caba0dd0SBarry Smith rstart = scale*rank; 58689d82c54SBarry Smith 58789d82c54SBarry Smith /* determine ownership ranges of global indices */ 5887c334f02SBarry Smith ierr = PetscMalloc(2*size*sizeof(PetscInt),&nprocs);CHKERRQ(ierr); 58932dcc486SBarry Smith ierr = PetscMemzero(nprocs,2*size*sizeof(PetscInt));CHKERRQ(ierr); 59089d82c54SBarry Smith 59189d82c54SBarry Smith /* determine owners of each local node */ 5927c334f02SBarry Smith ierr = PetscMalloc(n*sizeof(PetscInt),&owner);CHKERRQ(ierr); 59389d82c54SBarry Smith for (i=0; i<n; i++) { 5943677ff5aSBarry Smith proc = lindices[i]/scale; /* processor that globally owns this index */ 59527c402fcSBarry Smith nprocs[2*proc+1] = 1; /* processor globally owns at least one of ours */ 5963677ff5aSBarry Smith owner[i] = proc; 59727c402fcSBarry Smith nprocs[2*proc]++; /* count of how many that processor globally owns of ours */ 59889d82c54SBarry Smith } 59927c402fcSBarry Smith nsends = 0; for (i=0; i<size; i++) nsends += nprocs[2*i+1]; 6001e2582c4SBarry Smith ierr = PetscInfo1(mapping,"Number of global owners for my local data %d\n",nsends);CHKERRQ(ierr); 60189d82c54SBarry Smith 60289d82c54SBarry Smith /* inform other processors of number of messages and max length*/ 60327c402fcSBarry Smith ierr = PetscMaxSum(comm,nprocs,&nmax,&nrecvs);CHKERRQ(ierr); 6041e2582c4SBarry Smith ierr = PetscInfo1(mapping,"Number of local owners for my global data %d\n",nrecvs);CHKERRQ(ierr); 60589d82c54SBarry Smith 60689d82c54SBarry Smith /* post receives for owned rows */ 60732dcc486SBarry Smith ierr = PetscMalloc((2*nrecvs+1)*(nmax+1)*sizeof(PetscInt),&recvs);CHKERRQ(ierr); 608b0a32e0cSBarry Smith ierr = PetscMalloc((nrecvs+1)*sizeof(MPI_Request),&recv_waits);CHKERRQ(ierr); 60989d82c54SBarry Smith for (i=0; i<nrecvs; i++) { 61032dcc486SBarry Smith ierr = MPI_Irecv(recvs+2*nmax*i,2*nmax,MPIU_INT,MPI_ANY_SOURCE,tag1,comm,recv_waits+i);CHKERRQ(ierr); 61189d82c54SBarry Smith } 61289d82c54SBarry Smith 61389d82c54SBarry Smith /* pack messages containing lists of local nodes to owners */ 61432dcc486SBarry Smith ierr = PetscMalloc((2*n+1)*sizeof(PetscInt),&sends);CHKERRQ(ierr); 61532dcc486SBarry Smith ierr = PetscMalloc((size+1)*sizeof(PetscInt),&starts);CHKERRQ(ierr); 61689d82c54SBarry Smith starts[0] = 0; 61727c402fcSBarry Smith for (i=1; i<size; i++) { starts[i] = starts[i-1] + 2*nprocs[2*i-2];} 61889d82c54SBarry Smith for (i=0; i<n; i++) { 61989d82c54SBarry Smith sends[starts[owner[i]]++] = lindices[i]; 62030dcb7c9SBarry Smith sends[starts[owner[i]]++] = i; 62189d82c54SBarry Smith } 62289d82c54SBarry Smith ierr = PetscFree(owner);CHKERRQ(ierr); 62389d82c54SBarry Smith starts[0] = 0; 62427c402fcSBarry Smith for (i=1; i<size; i++) { starts[i] = starts[i-1] + 2*nprocs[2*i-2];} 62589d82c54SBarry Smith 62689d82c54SBarry Smith /* send the messages */ 627b0a32e0cSBarry Smith ierr = PetscMalloc((nsends+1)*sizeof(MPI_Request),&send_waits);CHKERRQ(ierr); 62832dcc486SBarry Smith ierr = PetscMalloc((nsends+1)*sizeof(PetscInt),&dest);CHKERRQ(ierr); 62989d82c54SBarry Smith cnt = 0; 63089d82c54SBarry Smith for (i=0; i<size; i++) { 63127c402fcSBarry Smith if (nprocs[2*i]) { 63232dcc486SBarry Smith ierr = MPI_Isend(sends+starts[i],2*nprocs[2*i],MPIU_INT,i,tag1,comm,send_waits+cnt);CHKERRQ(ierr); 63330dcb7c9SBarry Smith dest[cnt] = i; 63489d82c54SBarry Smith cnt++; 63589d82c54SBarry Smith } 63689d82c54SBarry Smith } 63789d82c54SBarry Smith ierr = PetscFree(starts);CHKERRQ(ierr); 63889d82c54SBarry Smith 63989d82c54SBarry Smith /* wait on receives */ 64097f1f81fSBarry Smith ierr = PetscMalloc((nrecvs+1)*sizeof(PetscMPIInt),&source);CHKERRQ(ierr); 64197f1f81fSBarry Smith ierr = PetscMalloc((nrecvs+1)*sizeof(PetscMPIInt),&len);CHKERRQ(ierr); 64289d82c54SBarry Smith cnt = nrecvs; 64332dcc486SBarry Smith ierr = PetscMalloc((ng+1)*sizeof(PetscInt),&nownedsenders);CHKERRQ(ierr); 64432dcc486SBarry Smith ierr = PetscMemzero(nownedsenders,ng*sizeof(PetscInt));CHKERRQ(ierr); 64589d82c54SBarry Smith while (cnt) { 64689d82c54SBarry Smith ierr = MPI_Waitany(nrecvs,recv_waits,&imdex,&recv_status);CHKERRQ(ierr); 64789d82c54SBarry Smith /* unpack receives into our local space */ 64832dcc486SBarry Smith ierr = MPI_Get_count(&recv_status,MPIU_INT,&len[imdex]);CHKERRQ(ierr); 64989d82c54SBarry Smith source[imdex] = recv_status.MPI_SOURCE; 65030dcb7c9SBarry Smith len[imdex] = len[imdex]/2; 651caba0dd0SBarry Smith /* count how many local owners for each of my global owned indices */ 65230dcb7c9SBarry Smith for (i=0; i<len[imdex]; i++) nownedsenders[recvs[2*imdex*nmax+2*i]-rstart]++; 65389d82c54SBarry Smith cnt--; 65489d82c54SBarry Smith } 65589d82c54SBarry Smith ierr = PetscFree(recv_waits);CHKERRQ(ierr); 65689d82c54SBarry Smith 65730dcb7c9SBarry Smith /* count how many globally owned indices are on an edge multiplied by how many processors own them. */ 658bc8ff85bSBarry Smith nowned = 0; 659bc8ff85bSBarry Smith nownedm = 0; 660bc8ff85bSBarry Smith for (i=0; i<ng; i++) { 661bc8ff85bSBarry Smith if (nownedsenders[i] > 1) {nownedm += nownedsenders[i]; nowned++;} 662bc8ff85bSBarry Smith } 663bc8ff85bSBarry Smith 664bc8ff85bSBarry Smith /* create single array to contain rank of all local owners of each globally owned index */ 66532dcc486SBarry Smith ierr = PetscMalloc((nownedm+1)*sizeof(PetscInt),&ownedsenders);CHKERRQ(ierr); 66632dcc486SBarry Smith ierr = PetscMalloc((ng+1)*sizeof(PetscInt),&starts);CHKERRQ(ierr); 667bc8ff85bSBarry Smith starts[0] = 0; 668bc8ff85bSBarry Smith for (i=1; i<ng; i++) { 669bc8ff85bSBarry Smith if (nownedsenders[i-1] > 1) starts[i] = starts[i-1] + nownedsenders[i-1]; 670bc8ff85bSBarry Smith else starts[i] = starts[i-1]; 671bc8ff85bSBarry Smith } 672bc8ff85bSBarry Smith 67330dcb7c9SBarry Smith /* for each nontrival globally owned node list all arriving processors */ 674bc8ff85bSBarry Smith for (i=0; i<nrecvs; i++) { 675bc8ff85bSBarry Smith for (j=0; j<len[i]; j++) { 67630dcb7c9SBarry Smith node = recvs[2*i*nmax+2*j]-rstart; 677bc8ff85bSBarry Smith if (nownedsenders[node] > 1) { 678bc8ff85bSBarry Smith ownedsenders[starts[node]++] = source[i]; 679bc8ff85bSBarry Smith } 680bc8ff85bSBarry Smith } 681bc8ff85bSBarry Smith } 682bc8ff85bSBarry Smith 68307b52d57SBarry Smith if (debug) { /* ----------------------------------- */ 68430dcb7c9SBarry Smith starts[0] = 0; 68530dcb7c9SBarry Smith for (i=1; i<ng; i++) { 68630dcb7c9SBarry Smith if (nownedsenders[i-1] > 1) starts[i] = starts[i-1] + nownedsenders[i-1]; 68730dcb7c9SBarry Smith else starts[i] = starts[i-1]; 68830dcb7c9SBarry Smith } 68930dcb7c9SBarry Smith for (i=0; i<ng; i++) { 69030dcb7c9SBarry Smith if (nownedsenders[i] > 1) { 69130dcb7c9SBarry Smith ierr = PetscSynchronizedPrintf(comm,"[%d] global node %d local owner processors: ",rank,i+rstart);CHKERRQ(ierr); 69230dcb7c9SBarry Smith for (j=0; j<nownedsenders[i]; j++) { 69330dcb7c9SBarry Smith ierr = PetscSynchronizedPrintf(comm,"%d ",ownedsenders[starts[i]+j]);CHKERRQ(ierr); 69430dcb7c9SBarry Smith } 69530dcb7c9SBarry Smith ierr = PetscSynchronizedPrintf(comm,"\n");CHKERRQ(ierr); 69630dcb7c9SBarry Smith } 69730dcb7c9SBarry Smith } 69830dcb7c9SBarry Smith ierr = PetscSynchronizedFlush(comm);CHKERRQ(ierr); 69907b52d57SBarry Smith }/* ----------------------------------- */ 70030dcb7c9SBarry Smith 7013677ff5aSBarry Smith /* wait on original sends */ 7023a96401aSBarry Smith if (nsends) { 703b0a32e0cSBarry Smith ierr = PetscMalloc(nsends*sizeof(MPI_Status),&send_status);CHKERRQ(ierr); 7043a96401aSBarry Smith ierr = MPI_Waitall(nsends,send_waits,send_status);CHKERRQ(ierr); 7053a96401aSBarry Smith ierr = PetscFree(send_status);CHKERRQ(ierr); 7063a96401aSBarry Smith } 70789d82c54SBarry Smith ierr = PetscFree(send_waits);CHKERRQ(ierr); 7083a96401aSBarry Smith ierr = PetscFree(sends);CHKERRQ(ierr); 7093677ff5aSBarry Smith ierr = PetscFree(nprocs);CHKERRQ(ierr); 7103677ff5aSBarry Smith 7113677ff5aSBarry Smith /* pack messages to send back to local owners */ 71230dcb7c9SBarry Smith starts[0] = 0; 71330dcb7c9SBarry Smith for (i=1; i<ng; i++) { 71430dcb7c9SBarry Smith if (nownedsenders[i-1] > 1) starts[i] = starts[i-1] + nownedsenders[i-1]; 71530dcb7c9SBarry Smith else starts[i] = starts[i-1]; 71630dcb7c9SBarry Smith } 71730dcb7c9SBarry Smith nsends2 = nrecvs; 71832dcc486SBarry Smith ierr = PetscMalloc((nsends2+1)*sizeof(PetscInt),&nprocs);CHKERRQ(ierr); /* length of each message */ 71930dcb7c9SBarry Smith for (i=0; i<nrecvs; i++) { 72030dcb7c9SBarry Smith nprocs[i] = 1; 72130dcb7c9SBarry Smith for (j=0; j<len[i]; j++) { 72230dcb7c9SBarry Smith node = recvs[2*i*nmax+2*j]-rstart; 72330dcb7c9SBarry Smith if (nownedsenders[node] > 1) { 72430dcb7c9SBarry Smith nprocs[i] += 2 + nownedsenders[node]; 72530dcb7c9SBarry Smith } 72630dcb7c9SBarry Smith } 72730dcb7c9SBarry Smith } 72830dcb7c9SBarry Smith nt = 0; for (i=0; i<nsends2; i++) nt += nprocs[i]; 72932dcc486SBarry Smith ierr = PetscMalloc((nt+1)*sizeof(PetscInt),&sends2);CHKERRQ(ierr); 73032dcc486SBarry Smith ierr = PetscMalloc((nsends2+1)*sizeof(PetscInt),&starts2);CHKERRQ(ierr); 73130dcb7c9SBarry Smith starts2[0] = 0; for (i=1; i<nsends2; i++) starts2[i] = starts2[i-1] + nprocs[i-1]; 73230dcb7c9SBarry Smith /* 73330dcb7c9SBarry Smith Each message is 1 + nprocs[i] long, and consists of 73430dcb7c9SBarry Smith (0) the number of nodes being sent back 73530dcb7c9SBarry Smith (1) the local node number, 73630dcb7c9SBarry Smith (2) the number of processors sharing it, 73730dcb7c9SBarry Smith (3) the processors sharing it 73830dcb7c9SBarry Smith */ 73930dcb7c9SBarry Smith for (i=0; i<nsends2; i++) { 74030dcb7c9SBarry Smith cnt = 1; 74130dcb7c9SBarry Smith sends2[starts2[i]] = 0; 74230dcb7c9SBarry Smith for (j=0; j<len[i]; j++) { 74330dcb7c9SBarry Smith node = recvs[2*i*nmax+2*j]-rstart; 74430dcb7c9SBarry Smith if (nownedsenders[node] > 1) { 74530dcb7c9SBarry Smith sends2[starts2[i]]++; 74630dcb7c9SBarry Smith sends2[starts2[i]+cnt++] = recvs[2*i*nmax+2*j+1]; 74730dcb7c9SBarry Smith sends2[starts2[i]+cnt++] = nownedsenders[node]; 74832dcc486SBarry Smith ierr = PetscMemcpy(&sends2[starts2[i]+cnt],&ownedsenders[starts[node]],nownedsenders[node]*sizeof(PetscInt));CHKERRQ(ierr); 74930dcb7c9SBarry Smith cnt += nownedsenders[node]; 75030dcb7c9SBarry Smith } 75130dcb7c9SBarry Smith } 75230dcb7c9SBarry Smith } 75330dcb7c9SBarry Smith 75430dcb7c9SBarry Smith /* receive the message lengths */ 75530dcb7c9SBarry Smith nrecvs2 = nsends; 75632dcc486SBarry Smith ierr = PetscMalloc((nrecvs2+1)*sizeof(PetscInt),&lens2);CHKERRQ(ierr); 75732dcc486SBarry Smith ierr = PetscMalloc((nrecvs2+1)*sizeof(PetscInt),&starts3);CHKERRQ(ierr); 758d44834fbSBarry Smith ierr = PetscMalloc((nrecvs2+1)*sizeof(MPI_Request),&recv_waits);CHKERRQ(ierr); 75930dcb7c9SBarry Smith for (i=0; i<nrecvs2; i++) { 760d44834fbSBarry Smith ierr = MPI_Irecv(&lens2[i],1,MPIU_INT,dest[i],tag2,comm,recv_waits+i);CHKERRQ(ierr); 76130dcb7c9SBarry Smith } 762d44834fbSBarry Smith 7638a8e0b3aSBarry Smith /* send the message lengths */ 7648a8e0b3aSBarry Smith for (i=0; i<nsends2; i++) { 7658a8e0b3aSBarry Smith ierr = MPI_Send(&nprocs[i],1,MPIU_INT,source[i],tag2,comm);CHKERRQ(ierr); 7668a8e0b3aSBarry Smith } 7678a8e0b3aSBarry Smith 768d44834fbSBarry Smith /* wait on receives of lens */ 7690c468ba9SBarry Smith if (nrecvs2) { 7700c468ba9SBarry Smith ierr = PetscMalloc(nrecvs2*sizeof(MPI_Status),&recv_statuses);CHKERRQ(ierr); 771d44834fbSBarry Smith ierr = MPI_Waitall(nrecvs2,recv_waits,recv_statuses);CHKERRQ(ierr); 772d44834fbSBarry Smith ierr = PetscFree(recv_statuses);CHKERRQ(ierr); 7730c468ba9SBarry Smith } 774d44834fbSBarry Smith ierr = PetscFree(recv_waits); 775d44834fbSBarry Smith 77630dcb7c9SBarry Smith starts3[0] = 0; 777d44834fbSBarry Smith nt = 0; 77830dcb7c9SBarry Smith for (i=0; i<nrecvs2-1; i++) { 77930dcb7c9SBarry Smith starts3[i+1] = starts3[i] + lens2[i]; 780d44834fbSBarry Smith nt += lens2[i]; 78130dcb7c9SBarry Smith } 782d44834fbSBarry Smith nt += lens2[nrecvs2-1]; 783d44834fbSBarry Smith 78432dcc486SBarry Smith ierr = PetscMalloc((nt+1)*sizeof(PetscInt),&recvs2);CHKERRQ(ierr); 785b0a32e0cSBarry Smith ierr = PetscMalloc((nrecvs2+1)*sizeof(MPI_Request),&recv_waits);CHKERRQ(ierr); 78652b72c4aSBarry Smith for (i=0; i<nrecvs2; i++) { 78732dcc486SBarry Smith ierr = MPI_Irecv(recvs2+starts3[i],lens2[i],MPIU_INT,dest[i],tag3,comm,recv_waits+i);CHKERRQ(ierr); 78830dcb7c9SBarry Smith } 78930dcb7c9SBarry Smith 79030dcb7c9SBarry Smith /* send the messages */ 791b0a32e0cSBarry Smith ierr = PetscMalloc((nsends2+1)*sizeof(MPI_Request),&send_waits);CHKERRQ(ierr); 79230dcb7c9SBarry Smith for (i=0; i<nsends2; i++) { 79332dcc486SBarry Smith ierr = MPI_Isend(sends2+starts2[i],nprocs[i],MPIU_INT,source[i],tag3,comm,send_waits+i);CHKERRQ(ierr); 79430dcb7c9SBarry Smith } 79530dcb7c9SBarry Smith 79630dcb7c9SBarry Smith /* wait on receives */ 7970c468ba9SBarry Smith if (nrecvs2) { 7980c468ba9SBarry Smith ierr = PetscMalloc(nrecvs2*sizeof(MPI_Status),&recv_statuses);CHKERRQ(ierr); 79930dcb7c9SBarry Smith ierr = MPI_Waitall(nrecvs2,recv_waits,recv_statuses);CHKERRQ(ierr); 80030dcb7c9SBarry Smith ierr = PetscFree(recv_statuses);CHKERRQ(ierr); 8010c468ba9SBarry Smith } 80230dcb7c9SBarry Smith ierr = PetscFree(recv_waits);CHKERRQ(ierr); 80330dcb7c9SBarry Smith ierr = PetscFree(nprocs);CHKERRQ(ierr); 80430dcb7c9SBarry Smith 80507b52d57SBarry Smith if (debug) { /* ----------------------------------- */ 80630dcb7c9SBarry Smith cnt = 0; 80730dcb7c9SBarry Smith for (i=0; i<nrecvs2; i++) { 80830dcb7c9SBarry Smith nt = recvs2[cnt++]; 80930dcb7c9SBarry Smith for (j=0; j<nt; j++) { 81030dcb7c9SBarry Smith ierr = PetscSynchronizedPrintf(comm,"[%d] local node %d number of subdomains %d: ",rank,recvs2[cnt],recvs2[cnt+1]);CHKERRQ(ierr); 81130dcb7c9SBarry Smith for (k=0; k<recvs2[cnt+1]; k++) { 81230dcb7c9SBarry Smith ierr = PetscSynchronizedPrintf(comm,"%d ",recvs2[cnt+2+k]);CHKERRQ(ierr); 81330dcb7c9SBarry Smith } 81430dcb7c9SBarry Smith cnt += 2 + recvs2[cnt+1]; 81530dcb7c9SBarry Smith ierr = PetscSynchronizedPrintf(comm,"\n");CHKERRQ(ierr); 81630dcb7c9SBarry Smith } 81730dcb7c9SBarry Smith } 81830dcb7c9SBarry Smith ierr = PetscSynchronizedFlush(comm);CHKERRQ(ierr); 81907b52d57SBarry Smith } /* ----------------------------------- */ 82030dcb7c9SBarry Smith 82130dcb7c9SBarry Smith /* count number subdomains for each local node */ 82232dcc486SBarry Smith ierr = PetscMalloc(size*sizeof(PetscInt),&nprocs);CHKERRQ(ierr); 82332dcc486SBarry Smith ierr = PetscMemzero(nprocs,size*sizeof(PetscInt));CHKERRQ(ierr); 82430dcb7c9SBarry Smith cnt = 0; 82530dcb7c9SBarry Smith for (i=0; i<nrecvs2; i++) { 82630dcb7c9SBarry Smith nt = recvs2[cnt++]; 82730dcb7c9SBarry Smith for (j=0; j<nt; j++) { 82830dcb7c9SBarry Smith for (k=0; k<recvs2[cnt+1]; k++) { 82930dcb7c9SBarry Smith nprocs[recvs2[cnt+2+k]]++; 83030dcb7c9SBarry Smith } 83130dcb7c9SBarry Smith cnt += 2 + recvs2[cnt+1]; 83230dcb7c9SBarry Smith } 83330dcb7c9SBarry Smith } 83430dcb7c9SBarry Smith nt = 0; for (i=0; i<size; i++) nt += (nprocs[i] > 0); 83530dcb7c9SBarry Smith *nproc = nt; 83632dcc486SBarry Smith ierr = PetscMalloc((nt+1)*sizeof(PetscInt),procs);CHKERRQ(ierr); 83732dcc486SBarry Smith ierr = PetscMalloc((nt+1)*sizeof(PetscInt),numprocs);CHKERRQ(ierr); 83832dcc486SBarry Smith ierr = PetscMalloc((nt+1)*sizeof(PetscInt*),indices);CHKERRQ(ierr); 83932dcc486SBarry Smith ierr = PetscMalloc(size*sizeof(PetscInt),&bprocs);CHKERRQ(ierr); 84030dcb7c9SBarry Smith cnt = 0; 84130dcb7c9SBarry Smith for (i=0; i<size; i++) { 84230dcb7c9SBarry Smith if (nprocs[i] > 0) { 84330dcb7c9SBarry Smith bprocs[i] = cnt; 84430dcb7c9SBarry Smith (*procs)[cnt] = i; 84530dcb7c9SBarry Smith (*numprocs)[cnt] = nprocs[i]; 84632dcc486SBarry Smith ierr = PetscMalloc(nprocs[i]*sizeof(PetscInt),&(*indices)[cnt]);CHKERRQ(ierr); 84730dcb7c9SBarry Smith cnt++; 84830dcb7c9SBarry Smith } 84930dcb7c9SBarry Smith } 85030dcb7c9SBarry Smith 85130dcb7c9SBarry Smith /* make the list of subdomains for each nontrivial local node */ 85232dcc486SBarry Smith ierr = PetscMemzero(*numprocs,nt*sizeof(PetscInt));CHKERRQ(ierr); 85330dcb7c9SBarry Smith cnt = 0; 85430dcb7c9SBarry Smith for (i=0; i<nrecvs2; i++) { 85530dcb7c9SBarry Smith nt = recvs2[cnt++]; 85630dcb7c9SBarry Smith for (j=0; j<nt; j++) { 85730dcb7c9SBarry Smith for (k=0; k<recvs2[cnt+1]; k++) { 85830dcb7c9SBarry Smith (*indices)[bprocs[recvs2[cnt+2+k]]][(*numprocs)[bprocs[recvs2[cnt+2+k]]]++] = recvs2[cnt]; 85930dcb7c9SBarry Smith } 86030dcb7c9SBarry Smith cnt += 2 + recvs2[cnt+1]; 86130dcb7c9SBarry Smith } 86230dcb7c9SBarry Smith } 86330dcb7c9SBarry Smith ierr = PetscFree(bprocs);CHKERRQ(ierr); 86407b52d57SBarry Smith ierr = PetscFree(recvs2);CHKERRQ(ierr); 86530dcb7c9SBarry Smith 86607b52d57SBarry Smith /* sort the node indexing by their global numbers */ 86707b52d57SBarry Smith nt = *nproc; 86807b52d57SBarry Smith for (i=0; i<nt; i++) { 86932dcc486SBarry Smith ierr = PetscMalloc(((*numprocs)[i])*sizeof(PetscInt),&tmp);CHKERRQ(ierr); 87007b52d57SBarry Smith for (j=0; j<(*numprocs)[i]; j++) { 87107b52d57SBarry Smith tmp[j] = lindices[(*indices)[i][j]]; 87207b52d57SBarry Smith } 87307b52d57SBarry Smith ierr = PetscSortIntWithArray((*numprocs)[i],tmp,(*indices)[i]);CHKERRQ(ierr); 87407b52d57SBarry Smith ierr = PetscFree(tmp);CHKERRQ(ierr); 87507b52d57SBarry Smith } 87607b52d57SBarry Smith 87707b52d57SBarry Smith if (debug) { /* ----------------------------------- */ 87830dcb7c9SBarry Smith nt = *nproc; 87930dcb7c9SBarry Smith for (i=0; i<nt; i++) { 88030dcb7c9SBarry Smith ierr = PetscSynchronizedPrintf(comm,"[%d] subdomain %d number of indices %d: ",rank,(*procs)[i],(*numprocs)[i]);CHKERRQ(ierr); 88130dcb7c9SBarry Smith for (j=0; j<(*numprocs)[i]; j++) { 88230dcb7c9SBarry Smith ierr = PetscSynchronizedPrintf(comm,"%d ",(*indices)[i][j]);CHKERRQ(ierr); 88330dcb7c9SBarry Smith } 88430dcb7c9SBarry Smith ierr = PetscSynchronizedPrintf(comm,"\n");CHKERRQ(ierr); 88530dcb7c9SBarry Smith } 88630dcb7c9SBarry Smith ierr = PetscSynchronizedFlush(comm);CHKERRQ(ierr); 88707b52d57SBarry Smith } /* ----------------------------------- */ 88830dcb7c9SBarry Smith 88930dcb7c9SBarry Smith /* wait on sends */ 89030dcb7c9SBarry Smith if (nsends2) { 891b0a32e0cSBarry Smith ierr = PetscMalloc(nsends2*sizeof(MPI_Status),&send_status);CHKERRQ(ierr); 89230dcb7c9SBarry Smith ierr = MPI_Waitall(nsends2,send_waits,send_status);CHKERRQ(ierr); 89330dcb7c9SBarry Smith ierr = PetscFree(send_status);CHKERRQ(ierr); 89430dcb7c9SBarry Smith } 89530dcb7c9SBarry Smith 89630dcb7c9SBarry Smith ierr = PetscFree(starts3);CHKERRQ(ierr); 89730dcb7c9SBarry Smith ierr = PetscFree(dest);CHKERRQ(ierr); 89830dcb7c9SBarry Smith ierr = PetscFree(send_waits);CHKERRQ(ierr); 8993677ff5aSBarry Smith 900bc8ff85bSBarry Smith ierr = PetscFree(nownedsenders);CHKERRQ(ierr); 901bc8ff85bSBarry Smith ierr = PetscFree(ownedsenders);CHKERRQ(ierr); 902bc8ff85bSBarry Smith ierr = PetscFree(starts);CHKERRQ(ierr); 90330dcb7c9SBarry Smith ierr = PetscFree(starts2);CHKERRQ(ierr); 90430dcb7c9SBarry Smith ierr = PetscFree(lens2);CHKERRQ(ierr); 90589d82c54SBarry Smith 90689d82c54SBarry Smith ierr = PetscFree(source);CHKERRQ(ierr); 90797f1f81fSBarry Smith ierr = PetscFree(len);CHKERRQ(ierr); 90889d82c54SBarry Smith ierr = PetscFree(recvs);CHKERRQ(ierr); 9093a96401aSBarry Smith ierr = PetscFree(nprocs);CHKERRQ(ierr); 91030dcb7c9SBarry Smith ierr = PetscFree(sends2);CHKERRQ(ierr); 91124cf384cSBarry Smith 91224cf384cSBarry Smith /* put the information about myself as the first entry in the list */ 91324cf384cSBarry Smith first_procs = (*procs)[0]; 91424cf384cSBarry Smith first_numprocs = (*numprocs)[0]; 91524cf384cSBarry Smith first_indices = (*indices)[0]; 91624cf384cSBarry Smith for (i=0; i<*nproc; i++) { 91724cf384cSBarry Smith if ((*procs)[i] == rank) { 91824cf384cSBarry Smith (*procs)[0] = (*procs)[i]; 91924cf384cSBarry Smith (*numprocs)[0] = (*numprocs)[i]; 92024cf384cSBarry Smith (*indices)[0] = (*indices)[i]; 92124cf384cSBarry Smith (*procs)[i] = first_procs; 92224cf384cSBarry Smith (*numprocs)[i] = first_numprocs; 92324cf384cSBarry Smith (*indices)[i] = first_indices; 92424cf384cSBarry Smith break; 92524cf384cSBarry Smith } 92624cf384cSBarry Smith } 92789d82c54SBarry Smith PetscFunctionReturn(0); 92889d82c54SBarry Smith } 92989d82c54SBarry Smith 9304a2ae208SSatish Balay #undef __FUNCT__ 9314a2ae208SSatish Balay #define __FUNCT__ "ISLocalToGlobalMappingRestoreInfo" 93207b52d57SBarry Smith /*@C 93307b52d57SBarry Smith ISLocalToGlobalMappingRestoreInfo - Frees the memory allocated by ISLocalToGlobalMappingGetInfo() 93489d82c54SBarry Smith 93507b52d57SBarry Smith Collective on ISLocalToGlobalMapping 93607b52d57SBarry Smith 93707b52d57SBarry Smith Input Parameters: 93807b52d57SBarry Smith . mapping - the mapping from local to global indexing 93907b52d57SBarry Smith 94007b52d57SBarry Smith Output Parameter: 94107b52d57SBarry Smith + nproc - number of processors that are connected to this one 94207b52d57SBarry Smith . proc - neighboring processors 94307b52d57SBarry Smith . numproc - number of indices for each processor 94407b52d57SBarry Smith - indices - indices of local nodes shared with neighbor (sorted by global numbering) 94507b52d57SBarry Smith 94607b52d57SBarry Smith Level: advanced 94707b52d57SBarry Smith 94807b52d57SBarry Smith .seealso: ISLocalToGlobalMappingDestroy(), ISLocalToGlobalMappingCreateIS(), ISLocalToGlobalMappingCreate(), 94907b52d57SBarry Smith ISLocalToGlobalMappingGetInfo() 95007b52d57SBarry Smith @*/ 9510c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingRestoreInfo(ISLocalToGlobalMapping mapping,PetscInt *nproc,PetscInt *procs[],PetscInt *numprocs[],PetscInt **indices[]) 95207b52d57SBarry Smith { 9536849ba73SBarry Smith PetscErrorCode ierr; 95432dcc486SBarry Smith PetscInt i; 95507b52d57SBarry Smith 95607b52d57SBarry Smith PetscFunctionBegin; 95705b42c5fSBarry Smith ierr = PetscFree(*procs);CHKERRQ(ierr); 95805b42c5fSBarry Smith ierr = PetscFree(*numprocs);CHKERRQ(ierr); 95900ff320aSBarry Smith if (*indices) { 96005b42c5fSBarry Smith ierr = PetscFree((*indices)[0]);CHKERRQ(ierr); 96100ff320aSBarry Smith for (i=1; i<*nproc; i++) { 96205b42c5fSBarry Smith ierr = PetscFree((*indices)[i]);CHKERRQ(ierr); 96307b52d57SBarry Smith } 96407b52d57SBarry Smith ierr = PetscFree(*indices);CHKERRQ(ierr); 96524cf384cSBarry Smith } 96607b52d57SBarry Smith PetscFunctionReturn(0); 96707b52d57SBarry Smith } 968