static char help[]= "Test PetscSFFetchAndOp on patterned SF graphs. PetscSFFetchAndOp internally uses PetscSFBcastAndOp \n\ and PetscSFReduce. So it is a good test to see if they all work for patterned graphs.\n\ Run with ./prog -op [replace | sum]\n\n"; #include #include int main(int argc,char **argv) { PetscInt i,N=10,low,high,nleaves; PetscMPIInt size,rank; Vec x,y,y2,gy2; PetscScalar *rootdata,*leafdata,*leafupdate; PetscLayout layout; PetscSF gathersf,allgathersf,alltoallsf; MPI_Op op=MPI_SUM; char opname[64]; const char *mpiopname; PetscBool flag,isreplace,issum; PetscFunctionBeginUser; PetscCall(PetscInitialize(&argc,&argv,(char*)0,help)); PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD,&size)); PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD,&rank)); PetscCall(PetscOptionsGetString(NULL,NULL,"-op",opname,sizeof(opname),&flag)); PetscCall(PetscStrcmp(opname,"replace",&isreplace)); PetscCall(PetscStrcmp(opname,"sum",&issum)); if (isreplace) {op = MPI_REPLACE; mpiopname = "MPI_REPLACE";} else if (issum) {op = MPIU_SUM; mpiopname = "MPI_SUM";} else SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Unsupported argument (%s) to -op, which must be 'replace' or 'sum'",opname); PetscCall(VecCreate(PETSC_COMM_WORLD,&x)); PetscCall(VecSetFromOptions(x)); PetscCall(VecSetSizes(x,PETSC_DECIDE,N)); /*-------------------------------------*/ /* PETSCSF_PATTERN_GATHER */ /*-------------------------------------*/ /* set MPI vec x to [1, 2, .., N] */ PetscCall(VecGetOwnershipRange(x,&low,&high)); for (i=low; i