From 8a42d4a7cdc62720bb5621caa4bdade4cff50d7f Mon Sep 17 00:00:00 2001 From: liu___yi <11356862+liu___yi@user.noreply.gitee.com> Date: Wed, 23 Nov 2022 17:10:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E6=E4=B8=AA=E5=8F=8C=E5=8F=82?= =?UTF-8?q?=E8=A1=A8=E8=BE=BE=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchMark.txt | 10 ++++-- benchMarkInterval.txt | 8 ++++- detectErrorTwoFPEDParallel.sh | 6 ++++ test2paramFPEDParallel.c | 67 ++++++++++++++++++++--------------- 4 files changed, 60 insertions(+), 31 deletions(-) diff --git a/benchMark.txt b/benchMark.txt index 84ffedf..eedee7a 100644 --- a/benchMark.txt +++ b/benchMark.txt @@ -26,7 +26,7 @@ sine x - (1.0/6.0)*x*x*x+(1.0/120.0)*x*x*x*x*x - (1.0/5040.0)*x*x*x*x*x*x*x sineorder3 (238732414637843.0/250000000000000.0)*x - (6450306886639899.0/50000000000000000.0)*x*x*x sqroot 1.0 + 0.5*x - 0.125*x*x + 0.0625*x*x*x - 0.0390625*x*x*x*x sqrt_add 1/(sqrt(x + 1) + sqrt(x)) -test05_nonlin1,r4 (x - 1)/(x*x - 1) +test05_nonlin1_r4 (x - 1)/(x*x - 1) test05_nonlin1_test2 1.0/(1+x) verhulst (4*x)/(1+x/1.11) ComplexSinCos 1.0/2.0*sin(r)*(exp(-i) - exp(i)) @@ -50,4 +50,10 @@ theta atan(x2/x1)*180/3.14159265359 turbine1 (2.0/(r*r)+3.0) - ((3.0 - 2.0*v)*(1.0/8.0)*((w*w)*r*r))/(1.0 - v) - 9.0/2.0 nonlin1 z/(z+1) carbonGas 35000000+(401.0/v)*(1000/v)*(v - 0.0427) - 0.0000000000000000041419509 -exp1x_32 (exp(x) - 1)/x \ No newline at end of file +exp1x_32 (exp(x) - 1)/x +carthesianToPolar_radius sqrt(((x * x) + (y * y))) +x_by_xy (x / (x + y)) +hypot sqrt(((x1 * x1) + (x2 * x2))) +himmilbeau ((((x1 * x1) + x2) - 11) * (((x1 * x1) + x2) - 11)) + (((x1 + (x2 * x2)) - 7) * ((x1 + (x2 * x2)) - 7)) +nonlin2 (((x * y) - 1) / (((x * y) * (x * y)) - 1)) +jetEngine (x1 + (((((((((2 * x1) * (((((3 * x1) * x1) + (2 * x2)) - x1) / ((x1 * x1) + 1))) * ((((((3 * x1) * x1) + (2 * x2)) - x1) / ((x1 * x1) + 1)) - 3)) + ((x1 * x1) * ((4 * (((((3 * x1) * x1) + (2 * x2)) - x1) / ((x1 * x1) + 1))) - 6))) * ((x1 * x1) + 1)) + (((3 * x1) * x1) * (((((3 * x1) * x1) + (2 * x2)) - x1) / ((x1 * x1) + 1)))) + ((x1 * x1) * x1)) + x1) + (3 * (((((3 * x1) * x1) - (2 * x2)) - x1) / ((x1 * x1) + 1))))) \ No newline at end of file diff --git a/benchMarkInterval.txt b/benchMarkInterval.txt index 8c85594..fcf6e30 100644 --- a/benchMarkInterval.txt +++ b/benchMarkInterval.txt @@ -50,4 +50,10 @@ 3.8 7.8 -4.5 -0.3 0.4 0.9 0 999 0.1 0.5 -0.01 0.5 \ No newline at end of file +0.01 0.5 +1 100 1 100 +1 4 1 4 +1 100 1 100 +-5 5 -5 5 +1.001 2 1.001 2 +-5 5 -20 5 \ No newline at end of file diff --git a/detectErrorTwoFPEDParallel.sh b/detectErrorTwoFPEDParallel.sh index 2bbbd08..611bda2 100755 --- a/detectErrorTwoFPEDParallel.sh +++ b/detectErrorTwoFPEDParallel.sh @@ -5,6 +5,12 @@ path=`pwd` cd ${path} CC=mpicc +uniqueLabel=${1} # unique number +x0Start=${2} +x0End=${3} +x1Start=${4} +x1End=${5} + if [ $# -eq 10 ]; then x0Size=${6} x1Size=${7} diff --git a/test2paramFPEDParallel.c b/test2paramFPEDParallel.c index 01b7710..4732a4f 100644 --- a/test2paramFPEDParallel.c +++ b/test2paramFPEDParallel.c @@ -27,7 +27,8 @@ struct errorInfo double EXPRESSIONMPFR(double, double, mpfr_t); double EXPRESSIONMINE(double, double); -int computeOrcle2param(double x0, double x1, mpfr_t orcle) { +int computeOrcle2param(double x0, double x1, mpfr_t orcle) +{ return EXPRESSIONMPFR(x0, x1, orcle); } @@ -41,16 +42,17 @@ int computeResult2param(double x0, double x1, mpfr_t mpfrResult) return status; } -struct errorInfo test2paramFPEDParallel(DL x0Start, DL x0End, DL x1Start, DL x1End, unsigned long int testNumX0, unsigned long int testNumX1, const char* fileNameKernel, int myid, int i1StartLocal, int i1EndLocal) { +struct errorInfo test2paramFPEDParallel(DL x0Start, DL x0End, DL x1Start, DL x1End, unsigned long int testNumX0, unsigned long int testNumX1, const char *fileNameKernel, int myid, int i1StartLocal, int i1EndLocal) +{ // printf("myid = %d: x0Start: %lg, x0End: %lg, x1Start: %lg, x1End: %lg\n", myid, x0Start.d, x0End.d, x1Start.d, x1End.d); DL maxInputX0, maxInputX1; int i0, i1; // int flag; double x0, x1, reUlp, sumError, aveReUlp, maxReUlp, lenX0, lenX1; - + // mpfr mpfr_t mpfrOrcle, mpfrResult; - mpfr_inits2(PRECISION, mpfrOrcle, mpfrResult, (mpfr_ptr) 0); + mpfr_inits2(PRECISION, mpfrOrcle, mpfrResult, (mpfr_ptr)0); // file // char *directory = "outputs"; @@ -60,7 +62,7 @@ struct errorInfo test2paramFPEDParallel(DL x0Start, DL x0End, DL x1Start, DL x1E // fileNameSample = (char *) calloc(strlen(fileNameKernel) + strlen(suffix) + 128, sizeof(char)); // sprintf(fileNameSample, "./%s/%s_%s_%d.txt", directory, fileNameKernel, suffix, myid); // printf("%s\n", fileNameSample); - // if ((f = fopen(fileNameSample, "w")) == NULL) { + // if ((f = fopen(fileNameSample, "w")) == NULL) { // printf("Error opening file %s.\n", fileNameSample); // exit(0); // } @@ -76,27 +78,31 @@ struct errorInfo test2paramFPEDParallel(DL x0Start, DL x0End, DL x1Start, DL x1E // flag = 1; // size_t testCount = 0; sumError = 0; - for(i1 = i1StartLocal; i1 <= i1EndLocal; i1++) { + for (i1 = i1StartLocal; i1 <= i1EndLocal; i1++) + { x1 = x1Start.d + stepX1 * i1; - for(i0 = 0; i0 <= (int)testNumX0; i0++) { + for (i0 = 0; i0 <= (int)testNumX0; i0++) + { x0 = x0Start.d + stepX0 * i0; computeResult2param(x0, x1, mpfrResult); computeOrcle2param(x0, x1, mpfrOrcle); - #ifdef SINGLE +#ifdef SINGLE reUlp = computeUlpDiffF(mpfrOrcle, mpfrResult); - #else // compute Double ULP as default +#else // compute Double ULP as default reUlp = computeUlpDiff(mpfrOrcle, mpfrResult); - #endif +#endif // if(reUlp <= 0.5) { // reUlp = 0; // } - // if(isfinite(reUlp) == 0) { - // printf("happen to NaN or inf\n"); - // exit(1); - // } + if (isfinite(reUlp) == 0) + { + printf("happen to NaN or inf\n"); + exit(1); + } // fprintf(f, "%le\t%le\t%e\n", x0, x1, reUlp); sumError += reUlp; - if (reUlp > maxReUlp) { + if (reUlp > maxReUlp) + { // flag = 0; maxInputX1.d = x1; maxInputX0.d = x0; @@ -116,7 +122,7 @@ struct errorInfo test2paramFPEDParallel(DL x0Start, DL x0End, DL x1Start, DL x1E // clear // fclose(f); // free(fileNameSample); - mpfr_clears(mpfrOrcle, mpfrResult, (mpfr_ptr) 0); + mpfr_clears(mpfrOrcle, mpfrResult, (mpfr_ptr)0); struct errorInfo err; err.sumError = sumError; err.maxError = maxReUlp; @@ -125,14 +131,15 @@ struct errorInfo test2paramFPEDParallel(DL x0Start, DL x0End, DL x1Start, DL x1E return err; } -int main(int argc, char **argv) { +int main(int argc, char **argv) +{ // parallel int myid, numProcs; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &myid); MPI_Comm_size(MPI_COMM_WORLD, &numProcs); MPI_Datatype MPI_errorInfo; - MPI_Type_contiguous(4, MPI_DOUBLE, &MPI_errorInfo); + MPI_Type_contiguous(4, MPI_DOUBLE, &MPI_errorInfo); MPI_Type_commit(&MPI_errorInfo); // parameters init @@ -146,7 +153,7 @@ int main(int argc, char **argv) { testNumX1 = TESTNUMX1; char *fileNameKernel; fileNameKernel = calloc(256, sizeof(char)); - if(argc == 8) + if (argc == 8) { x0Start.d = strtod(argv[1], NULL); x0End.d = strtod(argv[2], NULL); @@ -156,7 +163,7 @@ int main(int argc, char **argv) { testNumX1 = strtod(argv[6], NULL); strcpy(fileNameKernel, argv[7]); } - else if(argc == 6) + else if (argc == 6) { x0Start.d = strtod(argv[1], NULL); x0End.d = strtod(argv[2], NULL); @@ -164,7 +171,7 @@ int main(int argc, char **argv) { x1End.d = strtod(argv[4], NULL); strcpy(fileNameKernel, argv[5]); } - else if(argc == 4) + else if (argc == 4) { testNumX0 = strtod(argv[1], NULL); testNumX1 = strtod(argv[2], NULL); @@ -177,7 +184,8 @@ int main(int argc, char **argv) { printf("Usage: \tthe fixed inputs [%g %g %g %g %lu %lu] will be used\n", x0Start.d, x0End.d, x1Start.d, x1End.d, testNumX0, testNumX1); } - if(myid == 0) { + if (myid == 0) + { printf("\n---------------------------------------------------start test2paramFPEDParallel\n"); printf("Parameters: x0Start: %lg, x0End: %lg, x1Start: %lg, x1End: %lg, testNumX0 = %lu, testNumX1 = %lu, fileNameKernel: %s\n", x0Start.d, x0End.d, x1Start.d, x1End.d, testNumX0, testNumX1, fileNameKernel); } @@ -187,9 +195,12 @@ int main(int argc, char **argv) { int i1StartLocal; i1StartLocal = myid * lenX1Local; int i1EndLocal; - if(myid != numProcs - 1) { + if (myid != numProcs - 1) + { i1EndLocal = (myid + 1) * lenX1Local - 1; - } else { + } + else + { i1EndLocal = testNumX1; } @@ -200,16 +211,16 @@ int main(int argc, char **argv) { struct errorInfo *errs; errs = (struct errorInfo *)calloc(numProcs, sizeof(struct errorInfo)); MPI_Gather(&err, 1, MPI_errorInfo, errs, 1, MPI_errorInfo, 0, MPI_COMM_WORLD); - if(myid == 0) + if (myid == 0) { double maxError = -1; double aveError = 0; double errTmp = -1; int maxErrorIdx = -1; - for(int i = 0; i < numProcs; i++) + for (int i = 0; i < numProcs; i++) { errTmp = errs[i].maxError; - if(errTmp > maxError) + if (errTmp > maxError) { maxError = errTmp; maxErrorIdx = i; @@ -227,7 +238,7 @@ int main(int argc, char **argv) { char *fileNameErr; fileNameErr = (char *)calloc(strlen(directory) + strlen(fileNameKernel) + strlen(suffixErr) + 128, sizeof(char)); sprintf(fileNameErr, "%s/%s_%s", directory, fileNameKernel, suffixErr); - if((fErr = fopen(fileNameErr, "w")) == NULL) + if ((fErr = fopen(fileNameErr, "w")) == NULL) { printf("Error opening file %s.\n", fileNameErr); exit(0); -- Gitee