Commits

BarryFSmith committed 8fa295d

fixes for __float128 plus a memory corruption due to incorrectly sized array

Comments (0)

Files changed (7)

src/dm/examples/tests/ex42.c

 int main(int argc, char *argv[])
 {
   PetscErrorCode ierr;
-  ierr = PetscInitialize(&argc,&argv,0,help);CHKERRQ(ierr);
-  test_3d("3d.vtr");
-  test_2d("2d.vtr");
-  test_2d_nocoord("2d_nocoord.vtr");
-  test_3d_nocoord("3d_nocoord.vtr");
+  PetscInitialize(&argc,&argv,0,help);
+  ierr = test_3d("3d.vtr");CHKERRQ(ierr);
+  ierr = test_2d("2d.vtr");CHKERRQ(ierr);
+  ierr = test_2d_nocoord("2d_nocoord.vtr");CHKERRQ(ierr);
+  ierr = test_3d_nocoord("3d_nocoord.vtr");CHKERRQ(ierr);
   ierr = PetscFinalize();
   return 0;
 }

src/dm/impls/redundant/dmredundant.c

       if (imode == MAX_VALUES) for (i=0; i<red->N; i++) buffer[i] = PetscMax(gv[i],lv[i]);
 #endif
     } else source = (void*)lv;
-    ierr = MPI_Reduce(source,gv,red->N,MPIU_SCALAR,(imode == ADD_VALUES) ? MPI_SUM : MPI_MAX,red->rank,PetscObjectComm((PetscObject)dm));CHKERRQ(ierr);
+    ierr = MPI_Reduce(source,gv,red->N,MPIU_SCALAR,(imode == ADD_VALUES) ? MPIU_SUM : MPIU_MAX,red->rank,PetscObjectComm((PetscObject)dm));CHKERRQ(ierr);
 #if !defined(PETSC_HAVE_MPI_IN_PLACE)
     if (rank == red->rank) {ierr = PetscFree(buffer);CHKERRQ(ierr);}
 #endif

src/mat/interface/matnull.c

 {
   PetscErrorCode    ierr;
   const PetscScalar *x;
-  PetscScalar       *v[6],dots[3];
+  PetscScalar       *v[6],dots[6];
   Vec               vec[6];
   PetscInt          n,N,dim,nmodes,i,j;
 

src/snes/examples/tutorials/makefile

 	   else  printf "${PWD}\nPossible problem with with ex20_1, diffs above\n=========================================\n"; fi; \
 	   ${RM} -f ex20_1.tmp
 runex21:
-	-@${MPIEXEC} -n 4 ./ex21 -snes_linesearch_monitor -snes_mf -snes_monitor_short -nox -ksp_monitor -snes_converged_reason > ex21_1.tmp 2>&1; \
+	-@${MPIEXEC} -n 4 ./ex21 -snes_linesearch_monitor -snes_mf -snes_monitor_short -nox -ksp_monitor_short -snes_converged_reason > ex21_1.tmp 2>&1; \
 	   if (${DIFF} output/ex21_1.out ex21_1.tmp) then true; \
 	   else  printf "${PWD}\nPossible problem with with ex21_1, diffs above\n=========================================\n"; fi; \
 	   ${RM} -f ex21_1.tmp
 	   ${DIFF} output/ex58_2.out ex58.tmp || printf "${PWD}\nPossible problem with ex58_2, diffs above\n=========================================\n"; \
 	   ${RM} -f ex58.tmp
 runex73f90t:
-	-@${MPIEXEC} -n 4 ./ex73f90t -par 5.0 -da_grid_x 10 -da_grid_y 10 -snes_monitor -snes_linesearch_type basic -snes_converged_reason -ksp_type fgmres -ksp_norm_type unpreconditioned -pc_type fieldsplit -pc_fieldsplit_type schur -pc_fieldsplit_schur_fact_type upper -ksp_monitor -fieldsplit_lambda_ksp_type preonly -fieldsplit_lambda_pc_type jacobi -fieldsplit_lambda_ksp_monitor -fieldsplit_phi_pc_type gamg -fieldsplit_phi_pc_gamg_agg_nsmooths 1 -fieldsplit_phi_pc_gamg_threshold 0. -fieldsplit_phi_pc_gamg_verbose 2 -fieldsplit_phi_gamg_est_ksp_type cg
+	-@${MPIEXEC} -n 4 ./ex73f90t -par 5.0 -da_grid_x 10 -da_grid_y 10 -snes_monitor -snes_linesearch_type basic -snes_converged_reason -ksp_type fgmres -ksp_norm_type unpreconditioned -pc_type fieldsplit -pc_fieldsplit_type schur -pc_fieldsplit_schur_fact_type upper -ksp_monitor_short -fieldsplit_lambda_ksp_type preonly -fieldsplit_lambda_pc_type jacobi -fieldsplit_lambda_ksp_monitor_short -fieldsplit_phi_pc_type gamg -fieldsplit_phi_pc_gamg_agg_nsmooths 1 -fieldsplit_phi_pc_gamg_threshold 0. -fieldsplit_phi_pc_gamg_verbose 2 -fieldsplit_phi_gamg_est_ksp_type cg
 
 # This is way too slow  ex30.PETSc runex30 ex30.rm
 TESTEXAMPLES_C		       = ex1.PETSc runex1 runex1_2 ex1.rm ex2.PETSc runex2  runex2_3 ex2.rm ex3.PETSc runex3 \

src/snes/interface/snesut.c

 #endif
   PetscPrintf(PetscObjectComm((PetscObject)snes),"Eigenvalues of J_%d - J_%d:\n",it,it-1);CHKERRQ(ierr);
   for (i=0;i<n;i++) {
-    PetscPrintf(PetscObjectComm((PetscObject)snes),"%5d: %20.5g + %20.5gi\n",i,eigr[i],eigi[i]);CHKERRQ(ierr);
+    PetscPrintf(PetscObjectComm((PetscObject)snes),"%5d: %20.5g + %20.5gi\n",i,(double)eigr[i],(double)eigi[i]);CHKERRQ(ierr);
   }
   ierr = MatDenseRestoreArray(dJdense,&a);CHKERRQ(ierr);
   ierr = MatDestroy(&dJ);CHKERRQ(ierr);
   PetscFunctionBegin;
   ierr = PetscViewerASCIIAddTab(viewer,((PetscObject)snes)->tablevel);CHKERRQ(ierr);
   if (fgnorm > 1.e-9) {
-    ierr = PetscViewerASCIIPrintf(viewer,"%3D SNES Function norm %G \n",its,fgnorm);CHKERRQ(ierr);
+    ierr = PetscViewerASCIIPrintf(viewer,"%3D SNES Function norm %g \n",its,(double)fgnorm);CHKERRQ(ierr);
   } else if (fgnorm > 1.e-11) {
-    ierr = PetscViewerASCIIPrintf(viewer,"%3D SNES Function norm %5.3e \n",its,fgnorm);CHKERRQ(ierr);
+    ierr = PetscViewerASCIIPrintf(viewer,"%3D SNES Function norm %5.3e \n",its,(double)fgnorm);CHKERRQ(ierr);
   } else {
     ierr = PetscViewerASCIIPrintf(viewer,"%3D SNES Function norm < 1.e-11\n",its);CHKERRQ(ierr);
   }

src/sys/classes/random/examples/tutorials/ex2.c

 
 struct himaInfoTag {
   PetscInt    n;
-  double      r;
-  double      dt;
+  PetscReal   r;
+  PetscReal   dt;
   PetscInt    totalNumSim;
-  double      *St0;
-  double      *vol;
+  PetscReal   *St0;
+  PetscReal   *vol;
 };
 typedef struct himaInfoTag himaInfo;
 
-/* function protype */
 PetscErrorCode readData(MPI_Comm comm,himaInfo *hinfo);
-double mcVal(double St, double r, double vol, double dt, double eps);
-void exchange(double *a, double *b);
-double basketPayoff(double vol[], double St0[], PetscInt n, double r,double dt, double eps[]);
-void stdNormalArray(double *eps, PetscInt numdim,PetscRandom ran);
+PetscReal mcVal(PetscReal St, PetscReal r, PetscReal vol, PetscReal dt, PetscReal eps);
+void exchange(PetscReal *a, PetscReal *b);
+PetscReal basketPayoff(PetscReal vol[], PetscReal St0[], PetscInt n, PetscReal r,PetscReal dt, PetscReal eps[]);
+void stdNormalArray(PetscReal *eps, PetscInt numdim,PetscRandom ran);
 PetscInt divWork(PetscMPIInt id, PetscInt num, PetscMPIInt size);
 
 /*
 #define __FUNCT__ "main"
 int main(int argc, char *argv[])
 {
-  /* double         payoff; */
-  double         r,dt;
+  PetscReal      r,dt;
   PetscInt       n;
   unsigned long  i,myNumSim,totalNumSim,numdim;
-  double         *vol, *St0, x, totalx;
+  PetscReal      *vol, *St0, x, totalx;
   PetscMPIInt    size,rank;
-  double         *eps;
+  PetscReal      *eps;
   himaInfo       hinfo;
   PetscRandom    ran;
   PetscErrorCode ierr;
   r           = hinfo.r;
   dt          = hinfo.dt;
   totalNumSim = hinfo.totalNumSim;
-  vol         = hinfo.vol = (double*)malloc(sizeof(double)*(2*n+1));
+  vol         = hinfo.vol = (PetscReal*)malloc(sizeof(PetscReal)*(2*n+1));
   St0         = hinfo.St0 = hinfo.vol + n;
   ierr        = readData(PETSC_COMM_WORLD,&hinfo);CHKERRQ(ierr);
 
   numdim = n*(n+1)/2;
   if (numdim%2 == 1) numdim++;
-  eps = (double*)malloc(sizeof(double)*numdim);
+  eps = (PetscReal*)malloc(sizeof(PetscReal)*numdim);
 
   myNumSim = divWork(rank,totalNumSim,size);
 
     x += basketPayoff(vol,St0,n,r,dt,eps);
   }
 
-  ierr = MPI_Reduce(&x, &totalx, 1, MPI_DOUBLE, MPI_SUM,0,PETSC_COMM_WORLD);CHKERRQ(ierr);
+  ierr = MPI_Reduce(&x, &totalx, 1, MPIU_REAL, MPIU_SUM,0,PETSC_COMM_WORLD);CHKERRQ(ierr);
   /* payoff = exp(-r*dt*n)*(totalx/totalNumSim);
   ierr = PetscPrintf(PETSC_COMM_WORLD,"Option price = $%.3f using %ds of %s computation with %d %s for %d stocks, %d trading period per year, %.2f%% interest rate\n",
    payoff,(int)(stop - start),"parallel",size,"processors",n,(int)(1/dt),r);CHKERRQ(ierr); */
   return 0;
 }
 
-void stdNormalArray(double *eps, PetscInt numdim, PetscRandom ran)
+void stdNormalArray(PetscReal *eps, PetscInt numdim, PetscRandom ran)
 {
-  int            i;
-  double         u1,u2,t;
+  PetscInt       i;
+  PetscReal      u1,u2,t;
   PetscErrorCode ierr;
 
   for (i=0; i<numdim; i+=2) {
     ierr = PetscRandomGetValue(ran,(PetscScalar*)&u1);CHKERRABORT(PETSC_COMM_WORLD,ierr);
     ierr = PetscRandomGetValue(ran,(PetscScalar*)&u2);CHKERRABORT(PETSC_COMM_WORLD,ierr);
 
-    t        = sqrt(-2*log(u1));
-    eps[i]   = t * cos(2*PETSC_PI*u2);
-    eps[i+1] = t * sin(2*PETSC_PI*u2);
+    t        = PetscSqrtReal(-2*PetscLogReal(u1));
+    eps[i]   = t * PetscCosReal(2*PETSC_PI*u2);
+    eps[i+1] = t * PetscSinReal(2*PETSC_PI*u2);
   }
 }
 
 
-double basketPayoff(double vol[], double St0[], PetscInt n, double r,double dt, double eps[])
+PetscReal basketPayoff(PetscReal vol[], PetscReal St0[], PetscInt n, PetscReal r,PetscReal dt, PetscReal eps[])
 {
-  double Stk[PETSC_MAXBSIZE], temp;
-  double payoff;
-  PetscInt    maxk,i,j;
-  PetscInt    pointcount=0;
+  PetscReal Stk[PETSC_MAXBSIZE], temp;
+  PetscReal payoff;
+  PetscInt  maxk,i,j;
+  PetscInt  pointcount=0;
 
   for (i=0;i<n;i++) Stk[i] = St0[i];
 
 #define __FUNCT__ "readData"
 PetscErrorCode readData(MPI_Comm comm,himaInfo *hinfo)
 {
-  int            i;
+  PetscInt       i;
   FILE           *fd;
   char           temp[50];
   PetscErrorCode ierr;
   PetscMPIInt    rank;
-  double         *v = hinfo->vol, *t = hinfo->St0;
-  int            num=hinfo->n;
+  PetscReal      *v = hinfo->vol, *t = hinfo->St0;
+  PetscInt       num=hinfo->n;
 
   PetscFunctionBeginUser;
   ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
   if (!rank) {
     ierr = PetscFOpen(PETSC_COMM_SELF,DATAFILENAME,"r",&fd);CHKERRQ(ierr);
-    for (i=0;i<num;i++) fscanf(fd,"%s%lf%lf",temp,v+i,t+i);
+    for (i=0;i<num;i++) {
+      double vv,tt;
+      fscanf(fd,"%s%lf%lf",temp,&vv,&tt);
+      v[i] = vv;
+      t[i] = tt;
+    }
     fclose(fd);
   }
-  ierr = MPI_Bcast(v,2*num,MPI_DOUBLE,0,PETSC_COMM_WORLD);CHKERRQ(ierr);
+  ierr = MPI_Bcast(v,2*num,MPIU_REAL,0,PETSC_COMM_WORLD);CHKERRQ(ierr);
   /* ierr = PetscPrintf(PETSC_COMM_SELF,"[%d] vol %g, ... %g; St0 %g, ... %g\n",rank,hinfo->vol[0],hinfo->vol[num-1],hinfo->St0 [0],hinfo->St0[num-1]); */
   PetscFunctionReturn(0);
 }
 
-void exchange(double *a, double *b)
+void exchange(PetscReal *a, PetscReal *b)
 {
-  double t;
+  PetscReal t;
 
   t  = *a;
   *a = *b;
   *b = t;
 }
 
-double mcVal(double St, double r, double vol, double dt, double eps)
+PetscReal mcVal(PetscReal St, PetscReal r, PetscReal vol, PetscReal dt, PetscReal eps)
 {
-  return (St * exp((r-0.5*vol*vol)*dt + vol*sqrt(dt)*eps));
+  return (St * PetscExpReal((r-0.5*vol*vol)*dt + vol*PetscSqrtReal(dt)*eps));
 }
 
 PetscInt divWork(PetscMPIInt id, PetscInt num, PetscMPIInt size)
 {
   PetscInt numit;
 
-  numit = (PetscInt)(((double)num)/size);
+  numit = (PetscInt)(((PetscReal)num)/size);
   numit++;
   return numit;
 }

src/sys/utils/mathinf.c

 #if defined(PETSC_USE_REAL___FLOAT128)
 PetscBool PetscIsNormalScalar(PetscScalar a)
 {
-  return isnormalq(PetscAbsScalar(a));
+  return PETSC_TRUE;
 }
 PetscBool PetscIsNormalReal(PetscReal a)
 {
-  return isnormalq(a);
+  return PETSC_TRUE;
 }
 #elif defined(PETSC_HAVE_ISNORMAL)
 PetscBool PetscIsNormalScalar(PetscScalar a)