Mainly for debugging purposes: controlling format/precision could be convenient 
! 

Franck

~> mpirun -n 5 ./vecViewPrecision.exe 
Vec Object: 5 MPI processes
  type: mpi
Process [0]
0.
0.
Process [1]
1.23457e+06
-8.1e-07
Process [2]
2.46914e-06
-1.62e+06
Process [3]
3.7037e+06
-2.43e-06
Process [4]
4.93827e-06
-3.24e+06


----- Mail original -----
> De: "Jed Brown" <[email protected]>
> À: "Franck Houssen" <[email protected]>, "PETSc users list" 
> <[email protected]>
> Envoyé: Vendredi 26 Mai 2017 19:27:42
> Objet: Re: [petsc-users] How to VecView with a formatted precision (%10.8f) ?
> 
> No, but this could be added to the ASCII viewer.  Why do you want it?
> 
> Franck Houssen <[email protected]> writes:
> 
> > How to VecView with a formatted precision (%10.8f) ? Not possible ?
> >
> > Franck
> 
// How to control precision in VecView ?
//
// ~> g++ -o vecViewPrecision.exe vecViewPrecision.cpp -lpetsc -lm
// ~> mpirun -n 5 vecViewPrecision.exe

#include <iostream>
#include "petsc.h"

int main(int argc,char **argv) {
  PetscInitialize(&argc, &argv, NULL, NULL);
  int size = 0; MPI_Comm_size(MPI_COMM_WORLD, &size);
  int rank = 0; MPI_Comm_rank(MPI_COMM_WORLD, &rank);

  Vec v;
  VecCreateMPI(PETSC_COMM_WORLD, 2, 2*size, &v);

  double value = 1.23456789;
  double coef = (rank%2 == 0) ? 1.e-6 : 1.e+6; // Big/small values
  VecSetValue(v, 2*rank+0,  rank*value*coef, INSERT_VALUES);
  VecSetValue(v, 2*rank+1, -rank/value/coef, INSERT_VALUES);
  VecAssemblyBegin(v); VecAssemblyEnd(v);

  VecView(v, PETSC_VIEWER_STDOUT_WORLD);

  PetscFinalize();
  return 0;
}

Reply via email to