Actual source code: ex11.c

petsc-3.9.4 2018-09-11
Report Typos and Errors

  2: static char help[] = "Demonstrates PetscDataTypeFromString().\n\n";

  4: /*T
  5:    Concepts: introduction to PETSc;
  6:    Concepts: printing^in parallel
  7:    Processors: n
  8: T*/

 10:  #include <petscsys.h>
 11: int main(int argc,char **argv)
 12: {
 14:   PetscDataType  dtype;
 15:   PetscBool      found;

 17:   /*
 18:     Every PETSc routine should begin with the PetscInitialize() routine.
 19:     argc, argv - These command line arguments are taken to extract the options
 20:                  supplied to PETSc and options supplied to MPI.
 21:     help       - When PETSc executable is invoked with the option -help,
 22:                  it prints the various options that can be applied at
 23:                  runtime.  The user can use the "help" variable place
 24:                  additional help messages in this printout.
 25:   */
 26:   PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;

 28:   PetscDataTypeFromString("Scalar",&dtype,&found);
 29:   if (!found) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Did not find scalar datatype");
 30:   if (dtype != PETSC_SCALAR) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Found wrong datatype for scalar");

 32:   PetscDataTypeFromString("INT",&dtype,&found);
 33:   if (!found) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Did not find int datatype");
 34:   if (dtype != PETSC_INT) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Found wrong datatype for int");

 36:   PetscDataTypeFromString("real",&dtype,&found);
 37:   if (!found) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Did not find real datatype");
 38:   if (dtype != PETSC_REAL) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Found wrong datatype for real");

 40:   PetscDataTypeFromString("abogusdatatype",&dtype,&found);
 41:   if (found) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Found a bogus datatype");

 43:   PetscFinalize();
 44:   return ierr;
 45: }


 48: /*TEST

 50:    test:

 52: TEST*/