本文整理汇总了C++中ISGetLocalSize函数的典型用法代码示例。如果您正苦于以下问题:C++ ISGetLocalSize函数的具体用法?C++ ISGetLocalSize怎么用?C++ ISGetLocalSize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ISGetLocalSize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: array
/*@
ISConcatenate - Forms a new IS by locally concatenating the indices from an IS list without reordering.
Collective on comm.
Input Parameter:
+ comm - communicator of the concatenated IS.
. len - size of islist array (nonnegative)
- islist - array of index sets
Output Parameters:
. isout - The concatenated index set; empty, if len == 0.
Notes: The semantics of calling this on comm imply that the comms of the members if islist also contain this rank.
Level: intermediate
.seealso: ISDifference(), ISSum(), ISExpand()
Concepts: index sets^concatenation
Concepts: IS^concatenation
@*/
PetscErrorCode ISConcatenate(MPI_Comm comm, PetscInt len, const IS islist[], IS *isout)
{
PetscErrorCode ierr;
PetscInt i,n,N;
const PetscInt *iidx;
PetscInt *idx;
PetscFunctionBegin;
PetscValidPointer(islist,2);
#if defined(PETSC_USE_DEBUG)
for(i = 0; i < len; ++i) {
PetscValidHeaderSpecific(islist[i], IS_CLASSID, 1);
}
#endif
PetscValidPointer(isout, 5);
if(!len) {
ierr = ISCreateStride(comm, 0,0,0, isout); CHKERRQ(ierr);
PetscFunctionReturn(0);
}
if(len < 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Negative array length: %D", len);
N = 0;
for(i = 0; i < len; ++i) {
ierr = ISGetLocalSize(islist[i], &n); CHKERRQ(ierr);
N += n;
}
ierr = PetscMalloc(sizeof(PetscInt)*N, &idx); CHKERRQ(ierr);
N = 0;
for(i = 0; i < len; ++i) {
ierr = ISGetLocalSize(islist[i], &n); CHKERRQ(ierr);
ierr = ISGetIndices(islist[i], &iidx); CHKERRQ(ierr);
ierr = PetscMemcpy(idx+N,iidx, sizeof(PetscInt)*n); CHKERRQ(ierr);
N += n;
}
ierr = ISCreateGeneral(comm, N, idx, PETSC_OWN_POINTER, isout); CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例2: AOCreateBasic
/*@
AOApplicationToPetscIS - Maps an index set in the application-defined
ordering to the PETSc ordering.
Collective on AO and IS
Input Parameters:
+ ao - the application ordering context
- is - the index set; this is replaced with its mapped values
Output Parameter:
. is - the mapped index set
Level: beginner
Note:
The index set cannot be of type stride or block
Any integers in ia[] that are negative are left unchanged. This
allows one to convert, for example, neighbor lists that use negative
entries to indicate nonexistent neighbors due to boundary conditions, etc.
.keywords: application ordering, mapping
.seealso: AOCreateBasic(), AOView(), AOPetscToApplication(),
AOPetscToApplicationIS(), AOApplicationToPetsc()
@*/
PetscErrorCode AOApplicationToPetscIS(AO ao,IS is)
{
PetscErrorCode ierr;
PetscInt n,*ia;
PetscFunctionBegin;
PetscValidHeaderSpecific(ao,AO_CLASSID,1);
PetscValidHeaderSpecific(is,IS_CLASSID,2);
ierr = ISToGeneral(is);CHKERRQ(ierr);
/* we cheat because we know the is is general and that we can change the indices */
ierr = ISGetIndices(is,(const PetscInt**)&ia);CHKERRQ(ierr);
ierr = ISGetLocalSize(is,&n);CHKERRQ(ierr);
ierr = (*ao->ops->applicationtopetsc)(ao,n,ia);CHKERRQ(ierr);
ierr = ISRestoreIndices(is,(const PetscInt**)&ia);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例3: ISView_Block
static PetscErrorCode ISView_Block(IS is, PetscViewer viewer)
{
IS_Block *sub = (IS_Block*)is->data;
PetscErrorCode ierr;
PetscInt i,bs,n,*idx = sub->idx;
PetscBool iascii;
PetscFunctionBegin;
ierr = PetscLayoutGetBlockSize(is->map, &bs);CHKERRQ(ierr);
ierr = PetscLayoutGetLocalSize(is->map, &n);CHKERRQ(ierr);
n /= bs;
ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
if (iascii) {
PetscViewerFormat fmt;
ierr = PetscViewerGetFormat(viewer,&fmt);CHKERRQ(ierr);
if (fmt == PETSC_VIEWER_ASCII_MATLAB) {
IS ist;
const char *name;
const PetscInt *idx;
PetscInt n;
ierr = PetscObjectGetName((PetscObject)is,&name);CHKERRQ(ierr);
ierr = ISGetLocalSize(is,&n);CHKERRQ(ierr);
ierr = ISGetIndices(is,&idx);CHKERRQ(ierr);
ierr = ISCreateGeneral(PetscObjectComm((PetscObject)is),n,idx,PETSC_USE_POINTER,&ist);CHKERRQ(ierr);
ierr = PetscObjectSetName((PetscObject)ist,name);CHKERRQ(ierr);
ierr = ISView(ist,viewer);CHKERRQ(ierr);
ierr = ISDestroy(&ist);CHKERRQ(ierr);
ierr = ISRestoreIndices(is,&idx);CHKERRQ(ierr);
} else {
ierr = PetscViewerASCIIPushSynchronized(viewer);CHKERRQ(ierr);
if (is->isperm) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Block Index set is permutation\n");CHKERRQ(ierr);
}
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Block size %D\n",bs);CHKERRQ(ierr);
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Number of block indices in set %D\n",n);CHKERRQ(ierr);
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"The first indices of each block are\n");CHKERRQ(ierr);
for (i=0; i<n; i++) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Block %D Index %D\n",i,idx[i]);CHKERRQ(ierr);
}
ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
ierr = PetscViewerASCIIPopSynchronized(viewer);CHKERRQ(ierr);
}
}
PetscFunctionReturn(0);
}
示例4: MatPartitioningApply
/*@
ISPartitioningToNumbering - Takes an ISPartitioning and on each processor
generates an IS that contains a new global node number for each index based
on the partitioing.
Collective on IS
Input Parameters
. partitioning - a partitioning as generated by MatPartitioningApply()
Output Parameter:
. is - on each processor the index set that defines the global numbers
(in the new numbering) for all the nodes currently (before the partitioning)
on that processor
Level: advanced
.seealso: MatPartitioningCreate(), AOCreateBasic(), ISPartitioningCount()
@*/
PetscErrorCode ISPartitioningToNumbering(IS part,IS *is)
{
MPI_Comm comm;
PetscInt i,np,npt,n,*starts = NULL,*sums = NULL,*lsizes = NULL,*newi = NULL;
const PetscInt *indices = NULL;
PetscErrorCode ierr;
PetscFunctionBegin;
ierr = PetscObjectGetComm((PetscObject)part,&comm);CHKERRQ(ierr);
/* count the number of partitions, i.e., virtual processors */
ierr = ISGetLocalSize(part,&n);CHKERRQ(ierr);
ierr = ISGetIndices(part,&indices);CHKERRQ(ierr);
np = 0;
for (i=0; i<n; i++) np = PetscMax(np,indices[i]);
ierr = MPI_Allreduce(&np,&npt,1,MPIU_INT,MPI_MAX,comm);CHKERRQ(ierr);
np = npt+1; /* so that it looks like a MPI_Comm_size output */
/*
lsizes - number of elements of each partition on this particular processor
sums - total number of "previous" nodes for any particular partition
starts - global number of first element in each partition on this processor
*/
ierr = PetscMalloc3(np,&lsizes,np,&starts,np,&sums);CHKERRQ(ierr);
ierr = PetscMemzero(lsizes,np*sizeof(PetscInt));CHKERRQ(ierr);
for (i=0; i<n; i++) lsizes[indices[i]]++;
ierr = MPI_Allreduce(lsizes,sums,np,MPIU_INT,MPI_SUM,comm);CHKERRQ(ierr);
ierr = MPI_Scan(lsizes,starts,np,MPIU_INT,MPI_SUM,comm);CHKERRQ(ierr);
for (i=0; i<np; i++) starts[i] -= lsizes[i];
for (i=1; i<np; i++) {
sums[i] += sums[i-1];
starts[i] += sums[i-1];
}
/*
For each local index give it the new global number
*/
ierr = PetscMalloc1(n,&newi);CHKERRQ(ierr);
for (i=0; i<n; i++) newi[i] = starts[indices[i]]++;
ierr = PetscFree3(lsizes,starts,sums);CHKERRQ(ierr);
ierr = ISRestoreIndices(part,&indices);CHKERRQ(ierr);
ierr = ISCreateGeneral(comm,n,newi,PETSC_OWN_POINTER,is);CHKERRQ(ierr);
ierr = ISSetPermutation(*is);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例5: VecAXPY
/*@
VecISAXPY - Adds a reduced vector to the appropriate elements of a full-space vector.
vfull[is[i]] += alpha*vreduced[i]
Input Parameters:
+ vfull - the full-space vector
. vreduced - the reduced-space vector
- is - the index set for the reduced space
Output Parameters:
. vfull - the sum of the full-space vector and reduced-space vector
Level: advanced
.seealso: VecAXPY()
@*/
PetscErrorCode VecISAXPY(Vec vfull, IS is, PetscScalar alpha,Vec vreduced)
{
PetscInt nfull,nreduced;
MPI_Comm comm;
PetscErrorCode ierr;
PetscFunctionBegin;
PetscValidHeaderSpecific(vfull,VEC_CLASSID,1);
PetscValidHeaderSpecific(vreduced,VEC_CLASSID,2);
PetscValidHeaderSpecific(is,IS_CLASSID,3);
ierr = VecGetSize(vfull,&nfull);CHKERRQ(ierr);
ierr = VecGetSize(vreduced,&nreduced);CHKERRQ(ierr);
if (nfull == nreduced) { /* Also takes care of masked vectors */
ierr = VecAXPY(vfull,alpha,vreduced);CHKERRQ(ierr);
} else {
PetscScalar *y;
const PetscScalar *x;
PetscInt i,n,m,rstart;
const PetscInt *id;
ierr = PetscObjectGetComm((PetscObject)vfull,&comm);CHKERRQ(ierr);
ierr = VecGetArray(vfull,&y);CHKERRQ(ierr);
ierr = VecGetArrayRead(vreduced,&x);CHKERRQ(ierr);
ierr = ISGetIndices(is,&id);CHKERRQ(ierr);
ierr = ISGetLocalSize(is,&n);CHKERRQ(ierr);
ierr = VecGetLocalSize(vreduced,&m);CHKERRQ(ierr);
if (m != n) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"IS local length not equal to Vec local length");
ierr = VecGetOwnershipRange(vfull,&rstart,NULL);CHKERRQ(ierr);
y -= rstart;
if (alpha == 1.0) {
for (i=0; i<n; i++) {
y[id[i]] += x[i];
}
} else {
for (i=0; i<n; i++) {
y[id[i]] += alpha*x[i];
}
}
y += rstart;
ierr = ISRestoreIndices(is,&id);CHKERRQ(ierr);
ierr = VecRestoreArray(vfull,&y);CHKERRQ(ierr);
ierr = VecRestoreArrayRead(vreduced,&x);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
示例6: ISGetBlockGlobalIS
static PetscErrorCode ISGetBlockGlobalIS(IS is, Vec vec, PetscInt bs, IS *isBlockGlobal)
{
const PetscInt *idxin;
PetscInt *idxout, i, n, rstart;
PetscLayout map;
PetscErrorCode ierr;
PetscFunctionBegin;
ierr = VecGetLayout(vec,&map);CHKERRQ(ierr);
rstart = map->rstart / bs;
ierr = ISGetLocalSize(is, &n);CHKERRQ(ierr);
ierr = PetscMalloc1(n, &idxout);CHKERRQ(ierr);
ierr = ISGetIndices(is, &idxin);CHKERRQ(ierr);
for (i = 0; i < n; i++) idxout[i] = rstart + idxin[i];
ierr = ISRestoreIndices(is, &idxin);CHKERRQ(ierr);
ierr = ISCreateBlock(PetscObjectComm((PetscObject)vec),bs,n,idxout,PETSC_OWN_POINTER,isBlockGlobal);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例7: ISGatherTotal_Private
static PetscErrorCode ISGatherTotal_Private(IS is)
{
PetscErrorCode ierr;
PetscInt i,n,N;
const PetscInt *lindices;
MPI_Comm comm;
PetscMPIInt rank,size,*sizes = NULL,*offsets = NULL,nn;
PetscFunctionBegin;
PetscValidHeaderSpecific(is,IS_CLASSID,1);
ierr = PetscObjectGetComm((PetscObject)is,&comm);
CHKERRQ(ierr);
ierr = MPI_Comm_size(comm,&size);
CHKERRQ(ierr);
ierr = MPI_Comm_rank(comm,&rank);
CHKERRQ(ierr);
ierr = ISGetLocalSize(is,&n);
CHKERRQ(ierr);
ierr = PetscMalloc2(size,&sizes,size,&offsets);
CHKERRQ(ierr);
ierr = PetscMPIIntCast(n,&nn);
CHKERRQ(ierr);
ierr = MPI_Allgather(&nn,1,MPI_INT,sizes,1,MPI_INT,comm);
CHKERRQ(ierr);
offsets[0] = 0;
for (i=1; i<size; ++i) offsets[i] = offsets[i-1] + sizes[i-1];
N = offsets[size-1] + sizes[size-1];
ierr = PetscMalloc1(N,&(is->total));
CHKERRQ(ierr);
ierr = ISGetIndices(is,&lindices);
CHKERRQ(ierr);
ierr = MPI_Allgatherv((void*)lindices,nn,MPIU_INT,is->total,sizes,offsets,MPIU_INT,comm);
CHKERRQ(ierr);
ierr = ISRestoreIndices(is,&lindices);
CHKERRQ(ierr);
is->local_offset = offsets[rank];
ierr = PetscFree2(sizes,offsets);
CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例8: each
/*@
ISPartitioningCount - Takes a ISPartitioning and determines the number of
resulting elements on each (partition) process
Collective on IS
Input Parameters:
+ partitioning - a partitioning as generated by MatPartitioningApply()
- len - length of the array count, this is the total number of partitions
Output Parameter:
. count - array of length size, to contain the number of elements assigned
to each partition, where size is the number of partitions generated
(see notes below).
Level: advanced
Notes:
By default the number of partitions generated (and thus the length
of count) is the size of the communicator associated with IS,
but it can be set by MatPartitioningSetNParts. The resulting array
of lengths can for instance serve as input of PCBJacobiSetTotalBlocks.
.seealso: MatPartitioningCreate(), AOCreateBasic(), ISPartitioningToNumbering(),
MatPartitioningSetNParts(), MatPartitioningApply()
@*/
PetscErrorCode ISPartitioningCount(IS part,PetscInt len,PetscInt count[])
{
MPI_Comm comm;
PetscInt i,n,*lsizes;
const PetscInt *indices;
PetscErrorCode ierr;
PetscMPIInt npp;
PetscFunctionBegin;
ierr = PetscObjectGetComm((PetscObject)part,&comm);CHKERRQ(ierr);
if (len == PETSC_DEFAULT) {
PetscMPIInt size;
ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr);
len = (PetscInt) size;
}
/* count the number of partitions */
ierr = ISGetLocalSize(part,&n);CHKERRQ(ierr);
ierr = ISGetIndices(part,&indices);CHKERRQ(ierr);
#if defined(PETSC_USE_DEBUG)
{
PetscInt np = 0,npt;
for (i=0; i<n; i++) np = PetscMax(np,indices[i]);
ierr = MPI_Allreduce(&np,&npt,1,MPIU_INT,MPI_MAX,comm);CHKERRQ(ierr);
np = npt+1; /* so that it looks like a MPI_Comm_size output */
if (np > len) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_SIZ,"Length of count array %D is less than number of partitions %D",len,np);
}
#endif
/*
lsizes - number of elements of each partition on this particular processor
sums - total number of "previous" nodes for any particular partition
starts - global number of first element in each partition on this processor
*/
ierr = PetscMalloc(len*sizeof(PetscInt),&lsizes);CHKERRQ(ierr);
ierr = PetscMemzero(lsizes,len*sizeof(PetscInt));CHKERRQ(ierr);
for (i=0; i<n; i++) lsizes[indices[i]]++;
ierr = ISRestoreIndices(part,&indices);CHKERRQ(ierr);
ierr = PetscMPIIntCast(len,&npp);CHKERRQ(ierr);
ierr = MPI_Allreduce(lsizes,count,npp,MPIU_INT,MPI_SUM,comm);CHKERRQ(ierr);
ierr = PetscFree(lsizes);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例9: VecSetUp_NestIS_Private
static PetscErrorCode VecSetUp_NestIS_Private(Vec V,PetscInt nb,IS is[])
{
Vec_Nest *ctx = (Vec_Nest*)V->data;
PetscInt i,offset,m,n,M,N;
PetscErrorCode ierr;
PetscFunctionBegin;
if (is) { /* Do some consistency checks and reference the is */
offset = V->map->rstart;
for (i=0; i<ctx->nb; i++) {
ierr = ISGetSize(is[i],&M);CHKERRQ(ierr);
ierr = VecGetSize(ctx->v[i],&N);CHKERRQ(ierr);
if (M != N) SETERRQ3(PetscObjectComm((PetscObject)V),PETSC_ERR_ARG_INCOMP,"In slot %D, IS of size %D is not compatible with Vec of size %D",i,M,N);
ierr = ISGetLocalSize(is[i],&m);CHKERRQ(ierr);
ierr = VecGetLocalSize(ctx->v[i],&n);CHKERRQ(ierr);
if (m != n) SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_ARG_INCOMP,"In slot %D, IS of local size %D is not compatible with Vec of local size %D",i,m,n);
#if defined(PETSC_USE_DEBUG)
{ /* This test can be expensive */
PetscInt start;
PetscBool contiguous;
ierr = ISContiguousLocal(is[i],offset,offset+n,&start,&contiguous);CHKERRQ(ierr);
if (!contiguous) SETERRQ1(PetscObjectComm((PetscObject)V),PETSC_ERR_SUP,"Index set %D is not contiguous with layout of matching vector",i);
if (start != 0) SETERRQ1(PetscObjectComm((PetscObject)V),PETSC_ERR_SUP,"Index set %D introduces overlap or a hole",i);
}
#endif
ierr = PetscObjectReference((PetscObject)is[i]);CHKERRQ(ierr);
ctx->is[i] = is[i];
offset += n;
}
} else { /* Create a contiguous ISStride for each entry */
offset = V->map->rstart;
for (i=0; i<ctx->nb; i++) {
PetscInt bs;
ierr = VecGetLocalSize(ctx->v[i],&n);CHKERRQ(ierr);
ierr = VecGetBlockSize(ctx->v[i],&bs);CHKERRQ(ierr);
ierr = ISCreateStride(((PetscObject)ctx->v[i])->comm,n,offset,1,&ctx->is[i]);CHKERRQ(ierr);
ierr = ISSetBlockSize(ctx->is[i],bs);CHKERRQ(ierr);
offset += n;
}
}
PetscFunctionReturn(0);
}
示例10: main
int main(int argc,char **argv)
{
PetscInt i,n,start,stride;
const PetscInt *ii;
IS is;
PetscBool flg;
PetscErrorCode ierr;
ierr = PetscInitialize(&argc,&argv,(char*)0,help);CHKERRQ(ierr);
/*
Test IS of size 0
*/
ierr = ISCreateStride(PETSC_COMM_SELF,0,0,2,&is);CHKERRQ(ierr);
ierr = ISGetSize(is,&n);CHKERRQ(ierr);
if (n != 0) SETERRQ(PETSC_COMM_SELF,1,"ISCreateStride");
ierr = ISStrideGetInfo(is,&start,&stride);CHKERRQ(ierr);
if (start != 0) SETERRQ(PETSC_COMM_SELF,1,"ISStrideGetInfo");
if (stride != 2) SETERRQ(PETSC_COMM_SELF,1,"ISStrideGetInfo");
ierr = PetscObjectTypeCompare((PetscObject)is,ISSTRIDE,&flg);CHKERRQ(ierr);
if (!flg) SETERRQ(PETSC_COMM_SELF,1,"ISStride");
ierr = ISGetIndices(is,&ii);CHKERRQ(ierr);
ierr = ISRestoreIndices(is,&ii);CHKERRQ(ierr);
ierr = ISDestroy(&is);CHKERRQ(ierr);
/*
Test ISGetIndices()
*/
ierr = ISCreateStride(PETSC_COMM_SELF,10000,-8,3,&is);CHKERRQ(ierr);
ierr = ISGetLocalSize(is,&n);CHKERRQ(ierr);
ierr = ISGetIndices(is,&ii);CHKERRQ(ierr);
for (i=0; i<10000; i++) {
if (ii[i] != -8 + 3*i) SETERRQ(PETSC_COMM_SELF,1,"ISGetIndices");
}
ierr = ISRestoreIndices(is,&ii);CHKERRQ(ierr);
ierr = ISDestroy(&is);CHKERRQ(ierr);
ierr = PetscFinalize();
return 0;
}
示例11: set
/*@
ISComplement - Given an index set (IS) generates the complement index set. That is all
all indices that are NOT in the given set.
Collective on IS
Input Parameter:
+ is - the index set
. nmin - the first index desired in the local part of the complement
- nmax - the largest index desired in the local part of the complement (note that all indices in is must be greater or equal to nmin and less than nmax)
Output Parameter:
. isout - the complement
Notes: The communicator for this new IS is the same as for the input IS
For a parallel IS, this will generate the local part of the complement on each process
To generate the entire complement (on each process) of a parallel IS, first call ISAllGather() and then
call this routine.
Level: intermediate
Concepts: gather^index sets
Concepts: index sets^gathering to all processors
Concepts: IS^gathering to all processors
.seealso: ISCreateGeneral(), ISCreateStride(), ISCreateBlock(), ISAllGather()
@*/
PetscErrorCode ISComplement(IS is,PetscInt nmin,PetscInt nmax,IS *isout)
{
PetscErrorCode ierr;
const PetscInt *indices;
PetscInt n,i,j,unique,cnt,*nindices;
PetscBool sorted;
PetscFunctionBegin;
PetscValidHeaderSpecific(is,IS_CLASSID,1);
PetscValidPointer(isout,3);
if (nmin < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"nmin %D cannot be negative",nmin);
if (nmin > nmax) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"nmin %D cannot be greater than nmax %D",nmin,nmax);
ierr = ISSorted(is,&sorted);CHKERRQ(ierr);
if (!sorted) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Index set must be sorted");
ierr = ISGetLocalSize(is,&n);CHKERRQ(ierr);
ierr = ISGetIndices(is,&indices);CHKERRQ(ierr);
#if defined(PETSC_USE_DEBUG)
for (i=0; i<n; i++) {
if (indices[i] < nmin) SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Index %D's value %D is smaller than minimum given %D",i,indices[i],nmin);
if (indices[i] >= nmax) SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Index %D's value %D is larger than maximum given %D",i,indices[i],nmax);
}
#endif
/* Count number of unique entries */
unique = (n>0);
for (i=0; i<n-1; i++) {
if (indices[i+1] != indices[i]) unique++;
}
ierr = PetscMalloc1(nmax-nmin-unique,&nindices);CHKERRQ(ierr);
cnt = 0;
for (i=nmin,j=0; i<nmax; i++) {
if (j<n && i==indices[j]) do { j++; } while (j<n && i==indices[j]);
else nindices[cnt++] = i;
}
if (cnt != nmax-nmin-unique) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Number of entries found in complement %D does not match expected %D",cnt,nmax-nmin-unique);
ierr = ISCreateGeneral(PetscObjectComm((PetscObject)is),cnt,nindices,PETSC_OWN_POINTER,isout);CHKERRQ(ierr);
ierr = ISRestoreIndices(is,&indices);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例12: ISL2GCompose
/* Compose an IS with an ISLocalToGlobalMapping to map from IS source indices to global indices */
static PetscErrorCode ISL2GCompose(IS is,ISLocalToGlobalMapping ltog,ISLocalToGlobalMapping *cltog)
{
PetscErrorCode ierr;
const PetscInt *idx;
PetscInt m,*idxm;
PetscFunctionBegin;
PetscValidHeaderSpecific(is,IS_CLASSID,1);
PetscValidHeaderSpecific(ltog,IS_LTOGM_CLASSID,2);
PetscValidPointer(cltog,3);
ierr = ISGetLocalSize(is,&m);CHKERRQ(ierr);
ierr = ISGetIndices(is,&idx);CHKERRQ(ierr);
ierr = PetscMalloc1(m,&idxm);CHKERRQ(ierr);
if (ltog) {
ierr = ISLocalToGlobalMappingApply(ltog,m,idx,idxm);CHKERRQ(ierr);
} else {
ierr = PetscMemcpy(idxm,idx,m*sizeof(PetscInt));CHKERRQ(ierr);
}
ierr = ISLocalToGlobalMappingCreate(PetscObjectComm((PetscObject)is),m,idxm,PETSC_OWN_POINTER,cltog);CHKERRQ(ierr);
ierr = ISRestoreIndices(is,&idx);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例13: ISToGeneral_Block
static PetscErrorCode ISToGeneral_Block(IS inis)
{
IS_Block *sub = (IS_Block*)inis->data;
PetscInt bs,n;
const PetscInt *idx;
PetscErrorCode ierr;
PetscFunctionBegin;
ierr = ISGetBlockSize(inis,&bs);CHKERRQ(ierr);
ierr = ISGetLocalSize(inis,&n);CHKERRQ(ierr);
ierr = ISGetIndices(inis,&idx);CHKERRQ(ierr);
if (bs == 1) {
PetscCopyMode mode = sub->allocated ? PETSC_OWN_POINTER : PETSC_USE_POINTER;
sub->allocated = PETSC_FALSE; /* prevent deallocation when changing the subtype*/
ierr = ISSetType(inis,ISGENERAL);CHKERRQ(ierr);
ierr = ISGeneralSetIndices(inis,n,idx,mode);CHKERRQ(ierr);
} else {
ierr = ISSetType(inis,ISGENERAL);CHKERRQ(ierr);
ierr = ISGeneralSetIndices(inis,n,idx,PETSC_OWN_POINTER);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
示例14: DMLabelPermute
PetscErrorCode DMLabelPermute(DMLabel label, IS permutation, DMLabel *labelNew)
{
const PetscInt *perm;
PetscInt numValues, numPoints, v, q;
PetscErrorCode ierr;
PetscFunctionBegin;
ierr = DMLabelMakeAllValid_Private(label);CHKERRQ(ierr);
ierr = DMLabelDuplicate(label, labelNew);CHKERRQ(ierr);
ierr = DMLabelGetNumValues(*labelNew, &numValues);CHKERRQ(ierr);
ierr = ISGetLocalSize(permutation, &numPoints);CHKERRQ(ierr);
ierr = ISGetIndices(permutation, &perm);CHKERRQ(ierr);
for (v = 0; v < numValues; ++v) {
const PetscInt size = (*labelNew)->stratumSizes[v];
const PetscInt *points;
PetscInt *pointsNew;
ierr = ISGetIndices((*labelNew)->points[v],&points);CHKERRQ(ierr);
ierr = PetscMalloc1(size,&pointsNew);CHKERRQ(ierr);
for (q = 0; q < size; ++q) {
const PetscInt point = points[q];
if ((point < 0) || (point >= numPoints)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Label point %D is not in [0, %D) for the remapping", point, numPoints);
pointsNew[q] = perm[point];
}
ierr = ISRestoreIndices((*labelNew)->points[v],&points);CHKERRQ(ierr);
ierr = PetscSortInt(size, pointsNew);CHKERRQ(ierr);
ierr = ISDestroy(&((*labelNew)->points[v]));CHKERRQ(ierr);
ierr = ISCreateGeneral(PETSC_COMM_SELF,size,pointsNew,PETSC_OWN_POINTER,&((*labelNew)->points[v]));CHKERRQ(ierr);
ierr = PetscObjectSetName((PetscObject) ((*labelNew)->points[v]), "indices");CHKERRQ(ierr);
}
ierr = ISRestoreIndices(permutation, &perm);CHKERRQ(ierr);
if (label->bt) {
ierr = PetscBTDestroy(&label->bt);CHKERRQ(ierr);
ierr = DMLabelCreateIndex(label, label->pStart, label->pEnd);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
示例15: ISGetNonlocalIndices
/*@
ISGetNonlocalIS - Gather all nonlocal indices for this IS and present
them as another sequential index set.
Collective on IS
Input Parameter:
. is - the index set
Output Parameter:
. complement - sequential IS with indices identical to the result of
ISGetNonlocalIndices()
Level: intermediate
Notes: complement represents the result of ISGetNonlocalIndices as an IS.
Therefore scalability issues similar to ISGetNonlocalIndices apply.
The resulting IS must be restored using ISRestoreNonlocalIS().
Concepts: index sets^getting nonlocal indices
.seealso: ISGetNonlocalIndices(), ISRestoreNonlocalIndices(), ISAllGather(), ISGetSize()
@*/
PetscErrorCode ISGetNonlocalIS(IS is, IS *complement)
{
PetscErrorCode ierr;
PetscFunctionBegin;
PetscValidHeaderSpecific(is,IS_CLASSID,1);
PetscValidPointer(complement,2);
/* Check if the complement exists already. */
if (is->complement) {
*complement = is->complement;
ierr = PetscObjectReference((PetscObject)(is->complement));CHKERRQ(ierr);
} else {
PetscInt N, n;
const PetscInt *idx;
ierr = ISGetSize(is, &N);CHKERRQ(ierr);
ierr = ISGetLocalSize(is,&n);CHKERRQ(ierr);
ierr = ISGetNonlocalIndices(is, &idx);CHKERRQ(ierr);
ierr = ISCreateGeneral(PETSC_COMM_SELF, N-n,idx, PETSC_USE_POINTER, &(is->complement));CHKERRQ(ierr);
ierr = PetscObjectReference((PetscObject)is->complement);CHKERRQ(ierr);
*complement = is->complement;
}
PetscFunctionReturn(0);
}