/* * This file is part of libsharp. * * libsharp is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * libsharp is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with libsharp; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* * libsharp is being developed at the Max-Planck-Institut fuer Astrophysik * and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt * (DLR). */ /*! \file sharp_test.c Accuracy test for libsharp's map analysis. This program first generates a_lm coefficients up to a user-specified lmax (with mmax=lmax); where applicable, the real and imaginary parts of the coefficients are uniform random numbers of the interval [-1;1[. Afterwards, the random a_lm are converted to a map. This map is analyzed (optionally using an iterative scheme with a user-supplied number of steps). After every iteration, the code then outputs the RMS of the residual a_lm (i.e. the difference between the current and original a_lm), divided by the RMS of the original a_lm, as well as the maximum absolute change of any real or imaginary part between the current and original a_lm. This operation can be performed for several different pixelisations: - a Gaussian with the minimal number of rings for exact analysis and a user-defined ring resolution - an ECP grid with the minimal number of rings for exact analysis and a user-defined ring resolution - a Healpix grid with a user-defined Nside parameter. The user can specify the spin of the desired transform. Copyright (C) 2006-2012 Max-Planck-Society \author Martin Reinecke */ #include #include #ifdef USE_MPI #include "mpi.h" #endif #include "sharp.h" #include "sharp_geomhelpers.h" #include "sharp_almhelpers.h" #include "c_utils.h" #include "sharp_announce.h" #include "sharp_core.h" #include "memusage.h" typedef complex double dcmplx; static double drand (double min, double max) { return min + (max-min)*rand()/(RAND_MAX+1.0); } static void random_alm (dcmplx *alm, sharp_alm_info *helper, int spin) { for (int mi=0;minm; ++mi) { int m=helper->mval[mi]; for (int l=m;l<=helper->lmax; ++l) { if ((lmaxdiff) maxdiff=fabs(x); if (fabs(y)>maxdiff) maxdiff=fabs(y); } sum=sqrt(sum/nalms); sum2=sqrt(sum2/nalms); printf("component %i: rms %e, maxerr %e\n",i, sum/sum2, maxdiff); } } static void map2alm_iter (sharp_geom_info *tinfo, double **map, dcmplx **alm_orig, dcmplx **alm, int lmax, int mmax, ptrdiff_t npix, ptrdiff_t nalms, int spin, int ntrans, int niter) { int ncomp = ntrans*((spin==0) ? 1 : 2); sharp_alm_info *alms; sharp_make_triangular_alm_info(lmax,mmax,1,&alms); double time; unsigned long long opcnt; sharp_execute(SHARP_MAP2ALM,spin,0,&alm[0],&map[0],tinfo,alms,ntrans,1,0, &time,&opcnt); printf("wall time for map2alm: %fs\n",time); printf("Performance: %fGFLOPs/s\n",1e-9*opcnt/time); measure_errors(alm_orig,alm,nalms,ncomp); for (int iter=0; iter ",1); int lmax=atoi(argv[2]); int niter=atoi(argv[4]); int spin=atoi(argv[5]); int ntrans=atoi(argv[6]); printf("Testing map analysis accuracy.\n"); printf("lmax=%d, %d iterations, spin=%d\n", lmax, niter, spin); sharp_geom_info *tinfo; if (strcmp(argv[1],"gauss")==0) { int nrings=lmax+1; int ppring=atoi(argv[3]); ptrdiff_t npix=(ptrdiff_t)nrings*ppring; printf("\nTesting Gaussian grid (%d rings, %d pixels/ring, %ld pixels)\n", nrings,ppring,(long)npix); sharp_make_gauss_geom_info (nrings, ppring, 1, ppring, &tinfo); check_accuracy(tinfo,lmax,lmax,npix,spin,ntrans,niter); sharp_destroy_geom_info(tinfo); } else if (strcmp(argv[1],"ecp")==0) { int nrings=2*lmax+2; int ppring=atoi(argv[3]); ptrdiff_t npix=(ptrdiff_t)nrings*ppring; printf("\nTesting ECP grid (%d rings, %d pixels/ring, %ld pixels)\n", nrings,ppring,(long)npix); sharp_make_ecp_geom_info (nrings, ppring, 0., 1, ppring, &tinfo); check_accuracy(tinfo,lmax,lmax,npix,spin,ntrans,niter); sharp_destroy_geom_info(tinfo); } else if (strcmp(argv[1],"healpix")==0) { int nside=atoi(argv[3]); if (nside<1) nside=1; ptrdiff_t npix=12*(ptrdiff_t)nside*nside; printf("\nTesting Healpix grid (nside=%d, %ld pixels)\n", nside,(long)npix); sharp_make_healpix_geom_info (nside, 1, &tinfo); check_accuracy(tinfo,lmax,lmax,npix,spin,ntrans,niter); sharp_destroy_geom_info(tinfo); } else UTIL_FAIL("unknown grid geometry"); printf("\nMemory high water mark: %.2f MB\n",VmHWM()/(1<<20)); #ifdef USE_MPI MPI_Finalize(); #endif return 0; }