本文整理汇总了C++中ISGetLocalSize函数的典型用法代码示例。如果您正苦于以下问题:C++ ISGetLocalSize函数的具体用法?C++ ISGetLocalSize怎么用?C++ ISGetLocalSize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ISGetLocalSize函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:Kun-Qu,项目名称:petsc,代码行数:62,代码来源:isdiff.c
示例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);
}
开发者ID:00liujj,项目名称:petsc,代码行数:43,代码来源:ao.c
示例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);
}
开发者ID:firedrakeproject,项目名称:petsc,代码行数:47,代码来源:block.c
示例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);
}
开发者ID:haubentaucher,项目名称:petsc,代码行数:66,代码来源:iscoloring.c
示例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);
}
开发者ID:haubentaucher,项目名称:petsc,代码行数:62,代码来源:projection.c
示例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);
}
开发者ID:petsc,项目名称:petsc,代码行数:19,代码来源:ex1.c
示例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);
}
开发者ID:placasse,项目名称:petsc,代码行数:43,代码来源:index.c
示例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);
}
开发者ID:feelpp,项目名称:debian-petsc,代码行数:71,代码来源:iscoloring.c
示例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);
}
开发者ID:plguhur,项目名称:petsc,代码行数:42,代码来源:vecnest.c
示例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;
}
开发者ID:00liujj,项目名称:petsc,代码行数:40,代码来源:ex2.c
示例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);
}
开发者ID:haubentaucher,项目名称:petsc,代码行数:68,代码来源:iscoloring.c
示例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);
}
开发者ID:00liujj,项目名称:petsc,代码行数:23,代码来源:mlocalref.c
示例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);
}
开发者ID:firedrakeproject,项目名称:petsc,代码行数:22,代码来源:block.c
示例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);
}
开发者ID:ziolai,项目名称:petsc,代码行数:38,代码来源:dmlabel.c
示例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);
}
开发者ID:feelpp,项目名称:debian-petsc,代码行数:46,代码来源:index.c
示例16: ISGetSize
/*@C
ISGetNonlocalIndices - Retrieve an array of indices from remote processors
in this communicator.
Collective on IS
Input Parameter:
. is - the index set
Output Parameter:
. indices - indices with rank 0 indices first, and so on, omitting
the current rank. Total number of indices is the difference
total and local, obtained with ISGetSize() and ISGetLocalSize(),
respectively.
Level: intermediate
Notes: restore the indices using ISRestoreNonlocalIndices().
The same scalability considerations as those for ISGetTotalIndices
apply here.
Concepts: index sets^getting nonlocal indices
.seealso: ISGetTotalIndices(), ISRestoreNonlocalIndices(), ISGetSize(), ISGetLocalSize().
@*/
PetscErrorCode ISGetNonlocalIndices(IS is, const PetscInt *indices[])
{
PetscErrorCode ierr;
PetscMPIInt size;
PetscInt n, N;
PetscFunctionBegin;
PetscValidHeaderSpecific(is,IS_CLASSID,1);
PetscValidPointer(indices,2);
ierr = MPI_Comm_size(PetscObjectComm((PetscObject)is), &size);CHKERRQ(ierr);
if (size == 1) *indices = NULL;
else {
if (!is->total) {
ierr = ISGatherTotal_Private(is);CHKERRQ(ierr);
}
ierr = ISGetLocalSize(is,&n);CHKERRQ(ierr);
ierr = ISGetSize(is,&N);CHKERRQ(ierr);
ierr = PetscMalloc(sizeof(PetscInt)*(N-n), &(is->nonlocal));CHKERRQ(ierr);
ierr = PetscMemcpy(is->nonlocal, is->total, sizeof(PetscInt)*is->local_offset);CHKERRQ(ierr);
ierr = PetscMemcpy(is->nonlocal+is->local_offset, is->total+is->local_offset+n, sizeof(PetscInt)*(N - is->local_offset - n));CHKERRQ(ierr);
*indices = is->nonlocal;
}
PetscFunctionReturn(0);
}
开发者ID:feelpp,项目名称:debian-petsc,代码行数:48,代码来源:index.c
示例17: VecSet
/*@
VecISSet - Sets the elements of a vector, specified by an index set, to a constant
Input Parameter:
+ V - the vector
. S - the locations in the vector
- c - the constant
.seealso VecSet()
Level: advanced
@*/
PetscErrorCode VecISSet(Vec V,IS S, PetscScalar c)
{
PetscErrorCode ierr;
PetscInt nloc,low,high,i;
const PetscInt *s;
PetscScalar *v;
PetscFunctionBegin;
PetscValidHeaderSpecific(V,VEC_CLASSID,1);
PetscValidHeaderSpecific(S,IS_CLASSID,2);
PetscValidType(V,3);
PetscCheckSameComm(V,3,S,1);
ierr = VecGetOwnershipRange(V, &low, &high);CHKERRQ(ierr);
ierr = ISGetLocalSize(S,&nloc);CHKERRQ(ierr);
ierr = ISGetIndices(S, &s);CHKERRQ(ierr);
ierr = VecGetArray(V,&v);CHKERRQ(ierr);
for (i=0; i<nloc; i++){
v[s[i]-low] = c;
}
ierr = ISRestoreIndices(S, &s);CHKERRQ(ierr);
ierr = VecRestoreArray(V,&v);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
开发者ID:haubentaucher,项目名称:petsc,代码行数:36,代码来源:projection.c
示例18: MatPartitioningHierarchical_AssembleSubdomain
PetscErrorCode MatPartitioningHierarchical_AssembleSubdomain(Mat adj,IS destination,Mat *sadj, ISLocalToGlobalMapping *mapping)
{
IS irows,icols;
PetscInt irows_ln;
PetscMPIInt rank;
const PetscInt *irows_indices;
MPI_Comm comm;
PetscErrorCode ierr;
PetscFunctionBegin;
ierr = PetscObjectGetComm((PetscObject)adj,&comm);CHKERRQ(ierr);
ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
/* figure out where data comes from */
ierr = ISBuildTwoSided(destination,NULL,&irows);CHKERRQ(ierr);
ierr = ISDuplicate(irows,&icols);CHKERRQ(ierr);
ierr = ISGetLocalSize(irows,&irows_ln);CHKERRQ(ierr);
ierr = ISGetIndices(irows,&irows_indices);CHKERRQ(ierr);
ierr = ISLocalToGlobalMappingCreate(comm,1,irows_ln,irows_indices,PETSC_COPY_VALUES,mapping);CHKERRQ(ierr);
ierr = ISRestoreIndices(irows,&irows_indices);CHKERRQ(ierr);
ierr = MatGetSubMatrices(adj,1,&irows,&icols,MAT_INITIAL_MATRIX,&sadj);CHKERRQ(ierr);
ierr = ISDestroy(&irows);CHKERRQ(ierr);
ierr = ISDestroy(&icols);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
开发者ID:pombredanne,项目名称:petsc,代码行数:24,代码来源:hierarchical.c
示例19: ISView_General_HDF5
PetscErrorCode ISView_General_HDF5(IS is, PetscViewer viewer)
{
hid_t filespace; /* file dataspace identifier */
hid_t chunkspace; /* chunk dataset property identifier */
hid_t plist_id; /* property list identifier */
hid_t dset_id; /* dataset identifier */
hid_t memspace; /* memory dataspace identifier */
hid_t inttype; /* int type (H5T_NATIVE_INT or H5T_NATIVE_LLONG) */
hid_t file_id, group;
herr_t status;
hsize_t dim, maxDims[3], dims[3], chunkDims[3], count[3],offset[3];
PetscInt bs, N, n, timestep, low;
const PetscInt *ind;
const char *isname;
PetscErrorCode ierr;
PetscFunctionBegin;
ierr = ISGetBlockSize(is,&bs);CHKERRQ(ierr);
ierr = PetscViewerHDF5OpenGroup(viewer, &file_id, &group);CHKERRQ(ierr);
ierr = PetscViewerHDF5GetTimestep(viewer, ×tep);CHKERRQ(ierr);
/* Create the dataspace for the dataset.
*
* dims - holds the current dimensions of the dataset
*
* maxDims - holds the maximum dimensions of the dataset (unlimited
* for the number of time steps with the current dimensions for the
* other dimensions; so only additional time steps can be added).
*
* chunkDims - holds the size of a single time step (required to
* permit extending dataset).
*/
dim = 0;
if (timestep >= 0) {
dims[dim] = timestep+1;
maxDims[dim] = H5S_UNLIMITED;
chunkDims[dim] = 1;
++dim;
}
ierr = ISGetSize(is, &N);CHKERRQ(ierr);
ierr = ISGetLocalSize(is, &n);CHKERRQ(ierr);
ierr = PetscHDF5IntCast(N/bs,dims + dim);CHKERRQ(ierr);
maxDims[dim] = dims[dim];
chunkDims[dim] = dims[dim];
++dim;
if (bs >= 1) {
dims[dim] = bs;
maxDims[dim] = dims[dim];
chunkDims[dim] = dims[dim];
++dim;
}
filespace = H5Screate_simple(dim, dims, maxDims);
if (filespace == -1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Cannot H5Screate_simple()");
#if defined(PETSC_USE_64BIT_INDICES)
inttype = H5T_NATIVE_LLONG;
#else
inttype = H5T_NATIVE_INT;
#endif
/* Create the dataset with default properties and close filespace */
ierr = PetscObjectGetName((PetscObject) is, &isname);CHKERRQ(ierr);
if (!H5Lexists(group, isname, H5P_DEFAULT)) {
/* Create chunk */
chunkspace = H5Pcreate(H5P_DATASET_CREATE);
if (chunkspace == -1) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "Cannot H5Pcreate()");
status = H5Pset_chunk(chunkspace, dim, chunkDims);CHKERRQ(status);
#if (H5_VERS_MAJOR * 10000 + H5_VERS_MINOR * 100 + H5_VERS_RELEASE >= 10800)
dset_id = H5Dcreate2(group, isname, inttype, filespace, H5P_DEFAULT, chunkspace, H5P_DEFAULT);
#else
dset_id = H5Dcreate(group, isname, inttype, filespace, H5P_DEFAULT);
#endif
if (dset_id == -1) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "Cannot H5Dcreate2()");
status = H5Pclose(chunkspace);CHKERRQ(status);
} else {
dset_id = H5Dopen2(group, isname, H5P_DEFAULT);
status = H5Dset_extent(dset_id, dims);CHKERRQ(status);
}
status = H5Sclose(filespace);CHKERRQ(status);
/* Each process defines a dataset and writes it to the hyperslab in the file */
dim = 0;
if (timestep >= 0) {
count[dim] = 1;
++dim;
}
ierr = PetscHDF5IntCast(n/bs,count + dim);CHKERRQ(ierr);
++dim;
if (bs >= 1) {
count[dim] = bs;
++dim;
}
if (n > 0) {
memspace = H5Screate_simple(dim, count, NULL);
if (memspace == -1) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "Cannot H5Screate_simple()");
} else {
/* Can't create dataspace with zero for any dimension, so create null dataspace. */
memspace = H5Screate(H5S_NULL);
//.........这里部分代码省略.........
开发者ID:00liujj,项目名称:petsc,代码行数:101,代码来源:general.c
示例20: DMPlexVTKWriteAll_ASCII
static PetscErrorCode DMPlexVTKWriteAll_ASCII(DM dm, PetscViewer viewer)
{
MPI_Comm comm;
PetscViewer_VTK *vtk = (PetscViewer_VTK*) viewer->data;
FILE *fp;
PetscViewerVTKObjectLink link;
PetscSection coordSection, globalCoordSection;
PetscLayout vLayout;
Vec coordinates;
PetscReal lengthScale;
PetscInt vMax, totVertices, totCells;
PetscBool hasPoint = PETSC_FALSE, hasCell = PETSC_FALSE, writePartition = PETSC_FALSE;
PetscErrorCode ierr;
PetscFunctionBegin;
ierr = PetscObjectGetComm((PetscObject)dm,&comm);CHKERRQ(ierr);
ierr = PetscFOpen(comm, vtk->filename, "wb", &fp);CHKERRQ(ierr);
ierr = PetscFPrintf(comm, fp, "# vtk DataFile Version 2.0\n");CHKERRQ(ierr);
ierr = PetscFPrintf(comm, fp, "Simplicial Mesh Example\n");CHKERRQ(ierr);
ierr = PetscFPrintf(comm, fp, "ASCII\n");CHKERRQ(ierr);
ierr = PetscFPrintf(comm, fp, "DATASET UNSTRUCTURED_GRID\n");CHKERRQ(ierr);
/* Vertices */
ierr = DMPlexGetScale(dm, PETSC_UNIT_LENGTH, &lengthScale);CHKERRQ(ierr);
ierr = DMGetCoordinateSection(dm, &coordSection);CHKERRQ(ierr);
ierr = PetscSectionCreateGlobalSection(coordSection, dm->sf, PETSC_FALSE, PETSC_FALSE, &globalCoordSection);CHKERRQ(ierr);
ierr = DMGetCoordinatesLocal(dm, &coordinates);CHKERRQ(ierr);
ierr = DMPlexGetHybridBounds(dm, NULL, NULL, NULL, &vMax);CHKERRQ(ierr);
if (vMax >= 0) {
PetscInt pStart, pEnd, p, localSize = 0;
ierr = PetscSectionGetChart(globalCoordSection, &pStart, &pEnd);CHKERRQ(ierr);
pEnd = PetscMin(pEnd, vMax);
for (p = pStart; p < pEnd; ++p) {
PetscInt dof;
ierr = PetscSectionGetDof(globalCoordSection, p, &dof);CHKERRQ(ierr);
if (dof > 0) ++localSize;
}
ierr = PetscLayoutCreate(PetscObjectComm((PetscObject)dm), &vLayout);CHKERRQ(ierr);
ierr = PetscLayoutSetLocalSize(vLayout, localSize);CHKERRQ(ierr);
ierr = PetscLayoutSetBlockSize(vLayout, 1);CHKERRQ(ierr);
ierr = PetscLayoutSetUp(vLayout);CHKERRQ(ierr);
} else {
ierr = PetscSectionGetPointLayout(PetscObjectComm((PetscObject)dm), globalCoordSection, &vLayout);CHKERRQ(ierr);
}
ierr = PetscLayoutGetSize(vLayout, &totVertices);CHKERRQ(ierr);
ierr = PetscFPrintf(comm, fp, "POINTS %d double\n", totVertices);CHKERRQ(ierr);
ierr = DMPlexVTKWriteSection_ASCII(dm, coordSection, globalCoordSection, coordinates, fp, 3, PETSC_DETERMINE, lengthScale);CHKERRQ(ierr);
/* Cells */
ierr = DMPlexVTKWriteCells_ASCII(dm, fp, &totCells);CHKERRQ(ierr);
/* Vertex fields */
for (link = vtk->link; link; link = link->next) {
if ((link->ft == PETSC_VTK_POINT_FIELD) || (link->ft == PETSC_VTK_POINT_VECTOR_FIELD)) hasPoint = PETSC_TRUE;
i
|
请发表评论