Actual source code: ex21.c

petsc-3.13.4 2020-08-01
Report Typos and Errors

  2: static char help[] = "Tests VecMax() with index.\n\
  3:   -n <length> : vector length\n\n";

  5:  #include <petscvec.h>

  7: int main(int argc,char **argv)
  8: {
 10:   PetscInt       n = 5,idx;
 11:   PetscReal      value;
 12:   Vec            x;
 13:   PetscScalar    one = 1.0;

 15:   PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
 16:   PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);

 18:   /* create vector */
 19:   VecCreate(PETSC_COMM_WORLD,&x);
 20:   VecSetSizes(x,PETSC_DECIDE,n);
 21:   VecSetFromOptions(x);


 24:   VecSet(x,one);
 25:   VecSetValue(x,0,0.0,INSERT_VALUES);
 26:   VecSetValue(x,n-1,2.0,INSERT_VALUES);
 27:   VecAssemblyBegin(x);
 28:   VecAssemblyEnd(x);

 30:   VecView(x,PETSC_VIEWER_STDOUT_WORLD);
 31:   VecMax(x,&idx,&value);
 32:   PetscPrintf(PETSC_COMM_WORLD,"Maximum value %g index %D\n",(double)value,idx);
 33:   VecMin(x,&idx,&value);
 34:   PetscPrintf(PETSC_COMM_WORLD,"Minimum value %g index %D\n",(double)value,idx);

 36:   VecDestroy(&x);

 38:   PetscFinalize();
 39:   return ierr;
 40: }



 44: /*TEST
 45:    test:

 47:    test:
 48:       suffix: 2
 49:       nsize: 2

 51: TEST*/