本文整理汇总了C++中VecScatterCreate函数的典型用法代码示例。如果您正苦于以下问题:C++ VecScatterCreate函数的具体用法?C++ VecScatterCreate怎么用?C++ VecScatterCreate使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VecScatterCreate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: VecGetSize
void PetscVecTools::SetupInterleavedVectorScatterGather(Vec interleavedVec, VecScatter& rFirstVariableScatterContext, VecScatter& rSecondVariableScatterContext)
{
PetscInt num_rows, num_local_rows;
VecGetSize(interleavedVec, &num_rows);
VecGetLocalSize(interleavedVec, &num_local_rows);
IS A11_rows, A22_rows;
ISCreateStride(PETSC_COMM_WORLD, num_rows/2, 0, 2, &A11_rows);
ISCreateStride(PETSC_COMM_WORLD, num_rows/2, 1, 2, &A22_rows);
IS all_vector;
ISCreateStride(PETSC_COMM_WORLD, num_rows/2, 0, 1, &all_vector);
unsigned subvector_num_rows = num_rows/2;
unsigned subvector_local_rows = num_local_rows/2;
Vec x1_subvector = PetscTools::CreateVec(subvector_num_rows, subvector_local_rows);
Vec x2_subvector = PetscTools::CreateVec(subvector_num_rows, subvector_local_rows);
VecScatterCreate(interleavedVec, A11_rows, x1_subvector, all_vector, &rFirstVariableScatterContext);
VecScatterCreate(interleavedVec, A22_rows, x2_subvector, all_vector, &rSecondVariableScatterContext);
PetscTools::Destroy(x1_subvector);
PetscTools::Destroy(x2_subvector);
ISDestroy(PETSC_DESTROY_PARAM(A11_rows));
ISDestroy(PETSC_DESTROY_PARAM(A22_rows));
ISDestroy(PETSC_DESTROY_PARAM(all_vector));
}
示例2: RHSFunction
PetscErrorCode RHSFunction(TS ts,PetscReal t,Vec globalin,Vec globalout,void *ctx)
{
PetscScalar *inptr,*outptr;
PetscInt i,n,*idx;
PetscErrorCode ierr;
IS from,to;
VecScatter scatter;
Vec tmp_in,tmp_out;
/* Get the length of parallel vector */
ierr = VecGetSize(globalin,&n);CHKERRQ(ierr);
/* Set the index sets */
ierr = PetscMalloc(n*sizeof(PetscInt),&idx);CHKERRQ(ierr);
for(i=0; i<n; i++) idx[i]=i;
/* Create local sequential vectors */
ierr = VecCreateSeq(PETSC_COMM_SELF,n,&tmp_in);CHKERRQ(ierr);
ierr = VecDuplicate(tmp_in,&tmp_out);CHKERRQ(ierr);
/* Create scatter context */
ierr = ISCreateGeneral(PETSC_COMM_SELF,n,idx,PETSC_COPY_VALUES,&from);CHKERRQ(ierr);
ierr = ISCreateGeneral(PETSC_COMM_SELF,n,idx,PETSC_COPY_VALUES,&to);CHKERRQ(ierr);
ierr = VecScatterCreate(globalin,from,tmp_in,to,&scatter);CHKERRQ(ierr);
ierr = VecScatterBegin(scatter,globalin,tmp_in,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr);
ierr = VecScatterEnd(scatter,globalin,tmp_in,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr);
ierr = VecScatterDestroy(&scatter);CHKERRQ(ierr);
/*Extract income array */
ierr = VecGetArray(tmp_in,&inptr);CHKERRQ(ierr);
/* Extract outcome array*/
ierr = VecGetArray(tmp_out,&outptr);CHKERRQ(ierr);
outptr[0] = 2.0*inptr[0]+inptr[1];
outptr[1] = inptr[0]+2.0*inptr[1]+inptr[2];
outptr[2] = inptr[1]+2.0*inptr[2];
ierr = VecRestoreArray(tmp_in,&inptr);CHKERRQ(ierr);
ierr = VecRestoreArray(tmp_out,&outptr);CHKERRQ(ierr);
ierr = VecScatterCreate(tmp_out,from,globalout,to,&scatter);CHKERRQ(ierr);
ierr = VecScatterBegin(scatter,tmp_out,globalout,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr);
ierr = VecScatterEnd(scatter,tmp_out,globalout,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr);
/* Destroy idx aand scatter */
ierr = ISDestroy(&from);CHKERRQ(ierr);
ierr = ISDestroy(&to);CHKERRQ(ierr);
ierr = VecScatterDestroy(&scatter);CHKERRQ(ierr);
ierr = VecDestroy(&tmp_in);CHKERRQ(ierr);
ierr = VecDestroy(&tmp_out);CHKERRQ(ierr);
ierr = PetscFree(idx);CHKERRQ(ierr);
return 0;
}
示例3: main
int main(int argc,char **argv)
{
PetscErrorCode ierr;
AppCtx ctx;
TS ts;
Vec tsrhs,UV;
IS is;
PetscInt I;
PetscMPIInt rank;
PetscInitialize(&argc,&argv,(char*)0,help);
ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr);
ierr = TSCreate(PETSC_COMM_WORLD,&ts);CHKERRQ(ierr);
ierr = TSSetProblemType(ts,TS_NONLINEAR);CHKERRQ(ierr);
ierr = TSSetType(ts,TSROSW);CHKERRQ(ierr);
ierr = TSSetFromOptions(ts);CHKERRQ(ierr);
ierr = VecCreateMPI(PETSC_COMM_WORLD,2,PETSC_DETERMINE,&tsrhs);CHKERRQ(ierr);
ierr = VecCreateMPI(PETSC_COMM_WORLD,2,PETSC_DETERMINE,&UV);CHKERRQ(ierr);
ierr = TSSetRHSFunction(ts,tsrhs,TSFunctionRHS,&ctx);CHKERRQ(ierr);
ierr = TSSetIFunction(ts,NULL,TSFunctionI,&ctx);CHKERRQ(ierr);
ctx.f = f;
ctx.F = F;
ierr = VecCreateMPI(PETSC_COMM_WORLD,1,PETSC_DETERMINE,&ctx.U);CHKERRQ(ierr);
ierr = VecCreateMPI(PETSC_COMM_WORLD,1,PETSC_DETERMINE,&ctx.V);CHKERRQ(ierr);
ierr = VecCreateMPI(PETSC_COMM_WORLD,1,PETSC_DETERMINE,&ctx.UF);CHKERRQ(ierr);
ierr = VecCreateMPI(PETSC_COMM_WORLD,1,PETSC_DETERMINE,&ctx.VF);CHKERRQ(ierr);
I = 2*rank;
ierr = ISCreateGeneral(PETSC_COMM_WORLD,1,&I,PETSC_COPY_VALUES,&is);CHKERRQ(ierr);
ierr = VecScatterCreate(ctx.U,NULL,UV,is,&ctx.scatterU);CHKERRQ(ierr);
ierr = ISDestroy(&is);CHKERRQ(ierr);
I = 2*rank + 1;
ierr = ISCreateGeneral(PETSC_COMM_WORLD,1,&I,PETSC_COPY_VALUES,&is);CHKERRQ(ierr);
ierr = VecScatterCreate(ctx.V,NULL,UV,is,&ctx.scatterV);CHKERRQ(ierr);
ierr = ISDestroy(&is);CHKERRQ(ierr);
ierr = VecSet(UV,1.0);CHKERRQ(ierr);
ierr = TSSolve(ts,UV);CHKERRQ(ierr);
ierr = VecDestroy(&tsrhs);CHKERRQ(ierr);
ierr = VecDestroy(&UV);CHKERRQ(ierr);
ierr = VecDestroy(&ctx.U);CHKERRQ(ierr);
ierr = VecDestroy(&ctx.V);CHKERRQ(ierr);
ierr = VecDestroy(&ctx.UF);CHKERRQ(ierr);
ierr = VecDestroy(&ctx.VF);CHKERRQ(ierr);
ierr = VecScatterDestroy(&ctx.scatterU);CHKERRQ(ierr);
ierr = VecScatterDestroy(&ctx.scatterV);CHKERRQ(ierr);
ierr = TSDestroy(&ts);CHKERRQ(ierr);
PetscFinalize();
return 0;
}
示例4: DMDAGlobalToNaturalEnd
/*@
DMDAGlobalToNaturalAllCreate - Creates a scatter context that maps from the
global vector the entire vector to each processor in natural numbering
Collective on DMDA
Input Parameter:
. da - the distributed array context
Output Parameter:
. scatter - the scatter context
Level: advanced
.keywords: distributed array, global to local, begin, coarse problem
.seealso: DMDAGlobalToNaturalEnd(), DMLocalToGlobalBegin(), DMDACreate2d(),
DMGlobalToLocalBegin(), DMGlobalToLocalEnd(), DMDACreateNaturalVector()
@*/
PetscErrorCode DMDAGlobalToNaturalAllCreate(DM da,VecScatter *scatter)
{
PetscErrorCode ierr;
PetscInt N;
IS from,to;
Vec tmplocal,global;
AO ao;
DM_DA *dd = (DM_DA*)da->data;
PetscFunctionBegin;
PetscValidHeaderSpecific(da,DM_CLASSID,1);
PetscValidPointer(scatter,2);
ierr = DMDAGetAO(da,&ao);CHKERRQ(ierr);
/* create the scatter context */
ierr = VecCreateMPIWithArray(PetscObjectComm((PetscObject)da),dd->w,dd->Nlocal,PETSC_DETERMINE,0,&global);CHKERRQ(ierr);
ierr = VecGetSize(global,&N);CHKERRQ(ierr);
ierr = ISCreateStride(PetscObjectComm((PetscObject)da),N,0,1,&to);CHKERRQ(ierr);
ierr = AOPetscToApplicationIS(ao,to);CHKERRQ(ierr);
ierr = ISCreateStride(PetscObjectComm((PetscObject)da),N,0,1,&from);CHKERRQ(ierr);
ierr = VecCreateSeqWithArray(PETSC_COMM_SELF,dd->w,N,0,&tmplocal);CHKERRQ(ierr);
ierr = VecScatterCreate(global,from,tmplocal,to,scatter);CHKERRQ(ierr);
ierr = VecDestroy(&tmplocal);CHKERRQ(ierr);
ierr = VecDestroy(&global);CHKERRQ(ierr);
ierr = ISDestroy(&from);CHKERRQ(ierr);
ierr = ISDestroy(&to);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例5: main
int main(int argc,char **argv)
{
PetscErrorCode ierr;
PetscInt n = 5,N,low,high,iglobal,i;
PetscMPIInt size,rank;
PetscScalar value,zero = 0.0;
Vec x,y;
IS is1,is2;
VecScatter ctx;
ierr = PetscInitialize(&argc,&argv,(char*)0,help);CHKERRQ(ierr);
ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr);
ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr);
/* create two vectors */
N = size*n;
ierr = VecCreate(PETSC_COMM_WORLD,&y);CHKERRQ(ierr);
ierr = VecSetSizes(y,PETSC_DECIDE,N);CHKERRQ(ierr);
ierr = VecSetFromOptions(y);CHKERRQ(ierr);
if (!rank) {
ierr = VecCreateSeq(PETSC_COMM_SELF,N,&x);CHKERRQ(ierr);
} else {
ierr = VecCreateSeq(PETSC_COMM_SELF,0,&x);CHKERRQ(ierr);
}
/* create two index sets */
if (!rank) {
ierr = ISCreateStride(PETSC_COMM_SELF,N,0,1,&is1);CHKERRQ(ierr);
ierr = ISCreateStride(PETSC_COMM_SELF,N,0,1,&is2);CHKERRQ(ierr);
} else {
ierr = ISCreateStride(PETSC_COMM_SELF,0,0,1,&is1);CHKERRQ(ierr);
ierr = ISCreateStride(PETSC_COMM_SELF,0,0,1,&is2);CHKERRQ(ierr);
}
ierr = VecSet(x,zero);CHKERRQ(ierr);
ierr = VecGetOwnershipRange(y,&low,&high);CHKERRQ(ierr);
for (i=0; i<n; i++) {
iglobal = i + low; value = (PetscScalar) (i + 10*rank);
ierr = VecSetValues(y,1,&iglobal,&value,INSERT_VALUES);CHKERRQ(ierr);
}
ierr = VecAssemblyBegin(y);CHKERRQ(ierr);
ierr = VecAssemblyEnd(y);CHKERRQ(ierr);
ierr = VecView(y,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
ierr = VecScatterCreate(y,is2,x,is1,&ctx);CHKERRQ(ierr);
ierr = VecScatterBegin(ctx,y,x,ADD_VALUES,SCATTER_FORWARD);CHKERRQ(ierr);
ierr = VecScatterEnd(ctx,y,x,ADD_VALUES,SCATTER_FORWARD);CHKERRQ(ierr);
ierr = VecScatterDestroy(&ctx);CHKERRQ(ierr);
if (!rank)
{printf("----\n"); ierr = VecView(x,PETSC_VIEWER_STDOUT_SELF);CHKERRQ(ierr);}
ierr = VecDestroy(&x);CHKERRQ(ierr);
ierr = VecDestroy(&y);CHKERRQ(ierr);
ierr = ISDestroy(&is1);CHKERRQ(ierr);
ierr = ISDestroy(&is2);CHKERRQ(ierr);
ierr = PetscFinalize();
return 0;
}
示例6: MatSetLocalToGlobalMapping_IS
PetscErrorCode MatSetLocalToGlobalMapping_IS(Mat A,ISLocalToGlobalMapping rmapping,ISLocalToGlobalMapping cmapping)
{
PetscErrorCode ierr;
PetscInt n,bs;
Mat_IS *is = (Mat_IS*)A->data;
IS from,to;
Vec global;
PetscFunctionBegin;
PetscCheckSameComm(A,1,rmapping,2);
if (rmapping != cmapping) SETERRQ(PetscObjectComm((PetscObject)A),PETSC_ERR_ARG_INCOMP,"MATIS requires the row and column mappings to be identical");
if (is->mapping) { /* Currenly destroys the objects that will be created by this routine. Is there anything else that should be checked? */
ierr = ISLocalToGlobalMappingDestroy(&is->mapping);CHKERRQ(ierr);
ierr = VecDestroy(&is->x);CHKERRQ(ierr);
ierr = VecDestroy(&is->y);CHKERRQ(ierr);
ierr = VecScatterDestroy(&is->ctx);CHKERRQ(ierr);
ierr = MatDestroy(&is->A);CHKERRQ(ierr);
}
ierr = PetscObjectReference((PetscObject)rmapping);CHKERRQ(ierr);
ierr = ISLocalToGlobalMappingDestroy(&is->mapping);CHKERRQ(ierr);
is->mapping = rmapping;
/*
ierr = PetscLayoutSetISLocalToGlobalMapping(A->rmap,rmapping);CHKERRQ(ierr);
ierr = PetscLayoutSetISLocalToGlobalMapping(A->cmap,cmapping);CHKERRQ(ierr);
*/
/* Create the local matrix A */
ierr = ISLocalToGlobalMappingGetSize(rmapping,&n);CHKERRQ(ierr);
ierr = ISLocalToGlobalMappingGetBlockSize(rmapping,&bs);CHKERRQ(ierr);
ierr = MatCreate(PETSC_COMM_SELF,&is->A);CHKERRQ(ierr);
if (bs > 1) {
ierr = MatSetType(is->A,MATSEQBAIJ);CHKERRQ(ierr);
} else {
ierr = MatSetType(is->A,MATSEQAIJ);CHKERRQ(ierr);
}
ierr = MatSetSizes(is->A,n,n,n,n);CHKERRQ(ierr);
ierr = MatSetBlockSize(is->A,bs);CHKERRQ(ierr);
ierr = MatSetOptionsPrefix(is->A,((PetscObject)A)->prefix);CHKERRQ(ierr);
ierr = MatAppendOptionsPrefix(is->A,"is_");CHKERRQ(ierr);
ierr = MatSetFromOptions(is->A);CHKERRQ(ierr);
/* Create the local work vectors */
ierr = VecCreate(PETSC_COMM_SELF,&is->x);CHKERRQ(ierr);
ierr = VecSetBlockSize(is->x,bs);CHKERRQ(ierr);
ierr = VecSetSizes(is->x,n,n);CHKERRQ(ierr);
ierr = VecSetOptionsPrefix(is->x,((PetscObject)A)->prefix);CHKERRQ(ierr);
ierr = VecAppendOptionsPrefix(is->x,"is_");CHKERRQ(ierr);
ierr = VecSetFromOptions(is->x);CHKERRQ(ierr);
ierr = VecDuplicate(is->x,&is->y);CHKERRQ(ierr);
/* setup the global to local scatter */
ierr = ISCreateStride(PETSC_COMM_SELF,n,0,1,&to);CHKERRQ(ierr);
ierr = ISLocalToGlobalMappingApplyIS(rmapping,to,&from);CHKERRQ(ierr);
ierr = MatCreateVecs(A,&global,NULL);CHKERRQ(ierr);
ierr = VecScatterCreate(global,from,is->x,to,&is->ctx);CHKERRQ(ierr);
ierr = VecDestroy(&global);CHKERRQ(ierr);
ierr = ISDestroy(&to);CHKERRQ(ierr);
ierr = ISDestroy(&from);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例7: VecCreateSeqWithArray
void PetscVector::copyFromArray( double v[] )
{
int ierr;
Vec sv;
IS is;
VecScatter ctx;
ierr = VecCreateSeqWithArray(PETSC_COMM_SELF, n, v, &sv);
assert(ierr == 0);
ierr = ISCreateStride(PETSC_COMM_WORLD, n, 0, 1, &is);
assert( ierr == 0);
ierr = VecScatterCreate( sv, is, pv, is, &ctx);
assert( ierr == 0);
ierr = VecScatterBegin( sv, pv,INSERT_VALUES,SCATTER_FORWARD,
ctx);
assert( ierr == 0);
ierr = VecScatterEnd( sv, pv,INSERT_VALUES,SCATTER_FORWARD,
ctx);
assert( ierr == 0);
ierr = VecScatterDestroy(ctx);
assert( ierr == 0);
ierr = ISDestroy( is );
assert(ierr == 0);
ierr = VecDestroy( sv );
assert(ierr == 0);
}
示例8: setupIS
Real SAMpatchPETSc::normL2(const Vector& x, char dofType) const
{
#ifdef HAVE_MPI
if (adm.isParallel()) {
if (dofIS.find(dofType) == dofIS.end())
setupIS(dofType);
Vec lx;
VecCreateSeqWithArray(PETSC_COMM_SELF, 1, x.size(), x.data(), &lx);
Vec gx;
VecCreate(*adm.getCommunicator(), &gx);
VecSetSizes(gx, dofIS[dofType].nDofs, PETSC_DETERMINE);
VecSetFromOptions(gx);
PetscInt n;
VecGetSize(gx, &n);
if (!dofIS[dofType].scatterCreated) {
VecScatterCreate(lx, dofIS[dofType].local, gx, dofIS[dofType].global, &dofIS[dofType].ctx);
dofIS[dofType].scatterCreated = true;
}
VecScatterBegin(dofIS[dofType].ctx, lx, gx, INSERT_VALUES, SCATTER_FORWARD);
VecScatterEnd(dofIS[dofType].ctx, lx, gx, INSERT_VALUES, SCATTER_FORWARD);
PetscReal d;
VecNorm(gx, NORM_2, &d);
VecDestroy(&lx);
VecDestroy(&gx);
return d / sqrt(double(n));
}
#endif
return this->SAM::normL2(x, dofType);
}
示例9: VecDohpCreateDirichletCache
/** Create a cache for Dirichlet part of closure vector, and scatter from global closure to Dirichlet cache.
@arg[in] gvec Global vector
@arg[out] dcache New vector to hold the Dirichlet values
@arg[out] dscat Scatter from global closure to \a dcache
@note This could be local but it doesn't cost anything to make it global.
**/
dErr VecDohpCreateDirichletCache(Vec gvec,Vec *dcache,VecScatter *dscat)
{
MPI_Comm comm;
dErr err;
dBool isdohp;
IS from;
Vec gc;
dInt n,nc,crstart;
dFunctionBegin;
dValidHeader(gvec,VEC_CLASSID,1);
dValidPointer(dcache,2);
dValidPointer(dscat,3);
err = PetscTypeCompare((PetscObject)gvec,VECDOHP,&isdohp);dCHK(err);
if (!isdohp) dERROR(PETSC_COMM_SELF,PETSC_ERR_SUP,"Vec type %s",((PetscObject)gvec)->type_name);
err = PetscObjectGetComm((PetscObject)gvec,&comm);dCHK(err);
err = VecGetLocalSize(gvec,&n);dCHK(err);
err = VecDohpGetClosure(gvec,&gc);dCHK(err);
err = VecGetLocalSize(gc,&nc);dCHK(err);
err = VecGetOwnershipRange(gc,&crstart,NULL);dCHK(err);
err = VecCreateMPI(comm,nc-n,PETSC_DECIDE,dcache);dCHK(err);
err = ISCreateStride(comm,nc-n,crstart+n,1,&from);dCHK(err);
err = VecScatterCreate(gc,from,*dcache,NULL,dscat);dCHK(err);
err = VecDohpRestoreClosure(gvec,&gc);dCHK(err);
err = ISDestroy(&from);dCHK(err);
/* \todo deal with rotations */
dFunctionReturn(0);
}
示例10: MatSetUpMultiply_MPIDense
PetscErrorCode MatSetUpMultiply_MPIDense(Mat mat)
{
Mat_MPIDense *mdn = (Mat_MPIDense*)mat->data;
PetscErrorCode ierr;
IS from,to;
Vec gvec;
PetscFunctionBegin;
/* Create local vector that is used to scatter into */
ierr = VecCreateSeq(PETSC_COMM_SELF,mat->cmap->N,&mdn->lvec);CHKERRQ(ierr);
/* Create temporary index set for building scatter gather */
ierr = ISCreateStride(((PetscObject)mat)->comm,mat->cmap->N,0,1,&from);CHKERRQ(ierr);
ierr = ISCreateStride(PETSC_COMM_SELF,mat->cmap->N,0,1,&to);CHKERRQ(ierr);
/* Create temporary global vector to generate scatter context */
/* n = mdn->cowners[mdn->rank+1] - mdn->cowners[mdn->rank]; */
ierr = VecCreateMPIWithArray(((PetscObject)mat)->comm,1,mdn->nvec,mat->cmap->N,PETSC_NULL,&gvec);CHKERRQ(ierr);
/* Generate the scatter context */
ierr = VecScatterCreate(gvec,from,mdn->lvec,to,&mdn->Mvctx);CHKERRQ(ierr);
ierr = PetscLogObjectParent(mat,mdn->Mvctx);CHKERRQ(ierr);
ierr = PetscLogObjectParent(mat,mdn->lvec);CHKERRQ(ierr);
ierr = PetscLogObjectParent(mat,from);CHKERRQ(ierr);
ierr = PetscLogObjectParent(mat,to);CHKERRQ(ierr);
ierr = PetscLogObjectParent(mat,gvec);CHKERRQ(ierr);
ierr = ISDestroy(&to);CHKERRQ(ierr);
ierr = ISDestroy(&from);CHKERRQ(ierr);
ierr = VecDestroy(&gvec);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例11: RetrieveVecPoints
PetscErrorCode RetrieveVecPoints(Vec x, int Npt, int *Pos, double *ptValues)
{
PetscErrorCode ierr;
Vec T;
VecScatter scatter;
IS from, to;
ierr = VecCreateSeq(PETSC_COMM_SELF, Npt, &T);CHKERRQ(ierr);
ierr = ISCreateGeneral(PETSC_COMM_SELF,Npt, Pos,PETSC_COPY_VALUES, &from);CHKERRQ(ierr);
ierr = ISCreateStride(PETSC_COMM_SELF,Npt,0,1, &to);CHKERRQ(ierr);
ierr = VecScatterCreate(x,from,T,to,&scatter);CHKERRQ(ierr);
ierr = VecScatterBegin(scatter,x,T,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr);
ierr = VecScatterEnd(scatter,x,T,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr);
int ix[Npt];
int i;
for(i=0; i<Npt; i++)
ix[i]=i;
ierr = VecGetValues(T,Npt,ix,ptValues);
ierr = ISDestroy(&from);CHKERRQ(ierr);
ierr = ISDestroy(&to);CHKERRQ(ierr);
ierr = VecScatterDestroy(&scatter);CHKERRQ(ierr);
ierr = VecDestroy(&T);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例12: VecReorder
PetscErrorCode VecReorder(Vec r, Vec order, Vec or){
PetscErrorCode err;
PetscInt n_local, low, high;
PetscInt *to_idx, *from_idx;
PetscScalar *o_array;
IS to, from;
VecScatter scatter;
int i;
err = VecGetLocalSize(r, &n_local); CHKERRQ(err);
err = PetscMalloc1(n_local, &to_idx); CHKERRQ(err);
err = PetscMalloc1(n_local, &from_idx); CHKERRQ(err);
err = VecGetOwnershipRange(r, &low, &high); CHKERRQ(err);
err = VecGetArray(order, &o_array);
for(i = 0; i < n_local; i++){
to_idx[i] = (PetscInt) o_array[low + i];
from_idx[i] = (PetscInt) low + i;
}
err = VecRestoreArray(order, &o_array);
err = ISCreateGeneral(PETSC_COMM_SELF, n_local, from_idx, PETSC_OWN_POINTER, &to); CHKERRQ(err);
err = ISCreateGeneral(PETSC_COMM_SELF, n_local, from_idx, PETSC_OWN_POINTER, &from); CHKERRQ(err);
err = VecScatterCreate(r, from, or, to, &scatter); CHKERRQ(err);
err = VecScatterBegin(scatter, r, or, INSERT_VALUES, SCATTER_FORWARD); CHKERRQ(err);
err = VecScatterEnd(scatter, r, or, INSERT_VALUES, SCATTER_FORWARD); CHKERRQ(err);
err = PetscFree(to_idx); CHKERRQ(err);
err = PetscFree(from_idx); CHKERRQ(err);
return err;
}
示例13: NonlocalCollection
NonlocalCollection(Mat depends_on, IS interest_set) {
find_influences(depends_on, interest_set, &nodes);
PetscInt local_size;
ISGetLocalSize(nodes, &local_size);
VecCreateMPI(PETSC_COMM_WORLD, local_size, PETSC_DECIDE, &vec);
IS onto_index_set;
describe_partition(vec, &onto_index_set);
PetscInt begin;
PetscInt end;
VecGetOwnershipRange(vec, &begin, &end);
PetscInt *indicies;
ISGetIndices(nodes, &indicies);
assert(local_size == end-begin);
for (int ii=0; ii<local_size; ii++) {
map[indicies[ii]] = ii+begin;
}
ISRestoreIndices(nodes, &indicies);
Vec w;
MatGetVecs(depends_on, PETSC_NULL, &w);
VecScatterCreate(w, nodes, vec, onto_index_set, &scatter);
VecDestroy(w);
ISDestroy(onto_index_set);
}
示例14: ISCreateBlock
/*
Given a DMDA generates a VecScatter context that will deliver a slice
of the global vector to each processor. In this example, each processor
receives the values i=*, j=*, k=rank, i.e. one z plane.
Note: This code is written assuming only one degree of freedom per node.
For multiple degrees of freedom per node use ISCreateBlock()
instead of ISCreateGeneral().
*/
PetscErrorCode GenerateSliceScatter(DM da,VecScatter *scatter,Vec *vslice)
{
AO ao;
PetscInt M,N,P,nslice,*sliceindices,count,i,j;
PetscMPIInt rank;
PetscErrorCode ierr;
MPI_Comm comm;
Vec vglobal;
IS isfrom,isto;
ierr = PetscObjectGetComm((PetscObject)da,&comm);CHKERRQ(ierr);
ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
ierr = DMDAGetAO(da,&ao);CHKERRQ(ierr);
ierr = DMDAGetInfo(da,0,&M,&N,&P,0,0,0,0,0,0,0,0,0);CHKERRQ(ierr);
/*
nslice is number of degrees of freedom in this processors slice
if there are more processors then z plans the extra processors get 0
elements in their slice.
*/
if (rank < P) nslice = M*N;
else nslice = 0;
/*
Generate the local vector to hold this processors slice
*/
ierr = VecCreateSeq(PETSC_COMM_SELF,nslice,vslice);CHKERRQ(ierr);
ierr = DMCreateGlobalVector(da,&vglobal);CHKERRQ(ierr);
/*
Generate the indices for the slice in the "natural" global ordering
Note: this is just an example, one could select any subset of nodes
on each processor. Just list them in the global natural ordering.
*/
ierr = PetscMalloc1((nslice+1),&sliceindices);CHKERRQ(ierr);
count = 0;
if (rank < P) {
for (j=0; j<N; j++) {
for (i=0; i<M; i++) {
sliceindices[count++] = rank*M*N + j*M + i;
}
}
}
/*
Convert the indices to the "PETSc" global ordering
*/
ierr = AOApplicationToPetsc(ao,nslice,sliceindices);CHKERRQ(ierr);
/* Create the "from" and "to" index set */
/* This is to scatter from the global vector */
ierr = ISCreateGeneral(PETSC_COMM_SELF,nslice,sliceindices,PETSC_OWN_POINTER,&isfrom);CHKERRQ(ierr);
/* This is to gather into the local vector */
ierr = ISCreateStride(PETSC_COMM_SELF,nslice,0,1,&isto);CHKERRQ(ierr);
ierr = VecScatterCreate(vglobal,isfrom,*vslice,isto,scatter);CHKERRQ(ierr);
ierr = ISDestroy(&isfrom);CHKERRQ(ierr);
ierr = ISDestroy(&isto);CHKERRQ(ierr);
return 0;
}
示例15: PCBDDCScalingSetUp_Deluxe_Private
static PetscErrorCode PCBDDCScalingSetUp_Deluxe_Private(PC pc)
{
PC_BDDC *pcbddc=(PC_BDDC*)pc->data;
PCBDDCDeluxeScaling deluxe_ctx=pcbddc->deluxe_ctx;
PCBDDCSubSchurs sub_schurs = pcbddc->sub_schurs;
PetscErrorCode ierr;
PetscFunctionBegin;
if (!sub_schurs->n_subs) {
PetscFunctionReturn(0);
}
/* Create work vectors for sequential part of deluxe */
ierr = MatCreateVecs(sub_schurs->S_Ej_all,&deluxe_ctx->seq_work1,&deluxe_ctx->seq_work2);CHKERRQ(ierr);
/* Compute deluxe sequential scatter */
if (sub_schurs->reuse_mumps && !sub_schurs->is_dir) {
PCBDDCReuseMumps reuse_mumps = sub_schurs->reuse_mumps;
ierr = PetscObjectReference((PetscObject)reuse_mumps->correction_scatter_B);CHKERRQ(ierr);
deluxe_ctx->seq_scctx = reuse_mumps->correction_scatter_B;
} else {
ierr = VecScatterCreate(pcbddc->work_scaling,sub_schurs->is_Ej_all,deluxe_ctx->seq_work1,NULL,&deluxe_ctx->seq_scctx);CHKERRQ(ierr);
}
/* Create Mat object for deluxe scaling */
ierr = PetscObjectReference((PetscObject)sub_schurs->S_Ej_all);CHKERRQ(ierr);
deluxe_ctx->seq_mat = sub_schurs->S_Ej_all;
if (sub_schurs->sum_S_Ej_all) { /* if this matrix is present, then we need to create the KSP object to invert it */
PC pc_temp;
MatSolverPackage solver=NULL;
char ksp_prefix[256];
size_t len;
ierr = KSPCreate(PETSC_COMM_SELF,&deluxe_ctx->seq_ksp);CHKERRQ(ierr);
ierr = KSPSetOperators(deluxe_ctx->seq_ksp,sub_schurs->sum_S_Ej_all,sub_schurs->sum_S_Ej_all);CHKERRQ(ierr);
ierr = KSPSetType(deluxe_ctx->seq_ksp,KSPPREONLY);CHKERRQ(ierr);
ierr = KSPGetPC(deluxe_ctx->seq_ksp,&pc_temp);CHKERRQ(ierr);
ierr = PCSetType(pc_temp,PCLU);CHKERRQ(ierr);
ierr = KSPGetPC(pcbddc->ksp_D,&pc_temp);CHKERRQ(ierr);
ierr = PCFactorGetMatSolverPackage(pc_temp,(const MatSolverPackage*)&solver);CHKERRQ(ierr);
if (solver) {
PC new_pc;
PCType type;
ierr = PCGetType(pc_temp,&type);CHKERRQ(ierr);
ierr = KSPGetPC(deluxe_ctx->seq_ksp,&new_pc);CHKERRQ(ierr);
ierr = PCSetType(new_pc,type);CHKERRQ(ierr);
ierr = PCFactorSetMatSolverPackage(new_pc,solver);CHKERRQ(ierr);
}
ierr = PetscStrlen(((PetscObject)(pcbddc->ksp_D))->prefix,&len);CHKERRQ(ierr);
len -= 10; /* remove "dirichlet_" */
ierr = PetscStrncpy(ksp_prefix,((PetscObject)(pcbddc->ksp_D))->prefix,len+1);CHKERRQ(ierr);
ierr = PetscStrcat(ksp_prefix,"deluxe_");CHKERRQ(ierr);
ierr = KSPSetOptionsPrefix(deluxe_ctx->seq_ksp,ksp_prefix);CHKERRQ(ierr);
ierr = KSPSetFromOptions(deluxe_ctx->seq_ksp);CHKERRQ(ierr);
ierr = KSPSetUp(deluxe_ctx->seq_ksp);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}