static char help[]= "Test event log of VecScatter with various block sizes\n\n"; #include int main(int argc,char **argv) { PetscErrorCode ierr; PetscInt i,j,low,high,n=256,N,errors,tot_errors; PetscInt bs=1,ix[2],iy[2]; PetscMPIInt nproc,rank; PetscScalar *xval; const PetscScalar *yval; Vec x,y; IS isx,isy; VecScatter ctx; const PetscInt niter = 10; #if defined(PETSC_USE_LOG) PetscLogStage stage1,stage2; PetscLogEvent event1,event2; PetscLogDouble numMessages,messageLength; PetscEventPerfInfo eventInfo; PetscInt tot_msg,tot_len,avg_len; #endif PetscFunctionBegin; ierr = PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr; ierr = PetscLogDefaultBegin();CHKERRQ(ierr); ierr = MPI_Comm_size(PETSC_COMM_WORLD,&nproc);CHKERRMPI(ierr); ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRMPI(ierr); ierr = PetscLogStageRegister("Scatter(bs=1)", &stage1);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecScatter(bs=1)", PETSC_OBJECT_CLASSID, &event1);CHKERRQ(ierr); ierr = PetscLogStageRegister("Scatter(bs=4)", &stage2);CHKERRQ(ierr); ierr = PetscLogEventRegister("VecScatter(bs=4)", PETSC_OBJECT_CLASSID, &event2);CHKERRQ(ierr); /* Create a parallel vector x and a sequential vector y */ ierr = VecCreate(PETSC_COMM_WORLD,&x);CHKERRQ(ierr); ierr = VecSetSizes(x,n,PETSC_DECIDE);CHKERRQ(ierr); ierr = VecSetFromOptions(x);CHKERRQ(ierr); ierr = VecGetOwnershipRange(x,&low,&high);CHKERRQ(ierr); ierr = VecGetSize(x,&N);CHKERRQ(ierr); ierr = VecCreateSeq(PETSC_COMM_SELF,n,&y);CHKERRQ(ierr); /*======================================= test VecScatter with bs = 1 ======================================*/ /* the code works as if we are going to do 3-point stencil computations on a 1D domain x, which has periodic boundary conditions but the two ghosts are scatterred to beginning of y. */ bs = 1; ix[0] = rank? low-1 : N-1; /* ix[] contains global indices of the two ghost points */ ix[1] = (rank != nproc-1)? high : 0; iy[0] = 0; iy[1] = 1; ierr = ISCreateGeneral(PETSC_COMM_SELF,2,ix,PETSC_COPY_VALUES,&isx);CHKERRQ(ierr); ierr = ISCreateGeneral(PETSC_COMM_SELF,2,iy,PETSC_COPY_VALUES,&isy);CHKERRQ(ierr); ierr = VecScatterCreate(x,isx,y,isy,&ctx);CHKERRQ(ierr); ierr = VecScatterSetUp(ctx);CHKERRQ(ierr); ierr = PetscLogStagePush(stage1);CHKERRQ(ierr); ierr = PetscLogEventBegin(event1,0,0,0,0);CHKERRQ(ierr); errors = 0; for (i=0; i 2, tot_msg = 2*nproc*niter, tot_len = tot_msg*sizeof(PetscScalar)*bs */ ierr = PetscPrintf(PETSC_COMM_WORLD,"VecScatter(bs=%d) has sent out %d messages, total %d bytes, with average length %d bytes\n",bs,tot_msg,tot_len,avg_len);CHKERRQ(ierr); #endif ierr = ISDestroy(&isx);CHKERRQ(ierr); ierr = ISDestroy(&isy);CHKERRQ(ierr); ierr = VecScatterDestroy(&ctx);CHKERRQ(ierr); /*======================================= test VecScatter with bs = 4 ======================================*/ /* similar to the 3-point stencil above, except that this time a ghost is a block */ bs = 4; /* n needs to be a multiple of bs to make the following code work */ ix[0] = rank? low/bs-1 : N/bs-1; /* ix[] contains global indices of the two ghost blocks */ ix[1] = (rank != nproc-1)? high/bs : 0; iy[0] = 0; iy[1] = 1; ierr = ISCreateBlock(PETSC_COMM_SELF,bs,2,ix,PETSC_COPY_VALUES,&isx);CHKERRQ(ierr); ierr = ISCreateBlock(PETSC_COMM_SELF,bs,2,iy,PETSC_COPY_VALUES,&isy);CHKERRQ(ierr); ierr = VecScatterCreate(x,isx,y,isy,&ctx);CHKERRQ(ierr); /* Call SetUp explicitly, otherwise messages in implicit SetUp will be counted in events below */ ierr = VecScatterSetUp(ctx);CHKERRQ(ierr); ierr = PetscLogStagePush(stage2);CHKERRQ(ierr); ierr = PetscLogEventBegin(event2,0,0,0,0);CHKERRQ(ierr); errors = 0; for (i=0; i 2, tot_msg = 2*nproc*niter, tot_len = tot_msg*sizeof(PetscScalar)*bs */ ierr = PetscPrintf(PETSC_COMM_WORLD,"VecScatter(bs=%d) has sent out %d messages, total %d bytes, with average length %d bytes\n",bs,tot_msg,tot_len,avg_len);CHKERRQ(ierr); #endif ierr = PetscPrintf(PETSC_COMM_WORLD,"Program finished\n");CHKERRQ(ierr); ierr = ISDestroy(&isx);CHKERRQ(ierr); ierr = ISDestroy(&isy);CHKERRQ(ierr); ierr = VecScatterDestroy(&ctx);CHKERRQ(ierr); ierr = VecDestroy(&x);CHKERRQ(ierr); ierr = VecDestroy(&y);CHKERRQ(ierr); ierr = PetscFinalize(); return ierr; } /*TEST test: nsize: 4 args: requires: double define(PETSC_USE_LOG) TEST*/