NFFT  3.3.1
nfft_benchomp_detail.c
00001 /*
00002  * Copyright (c) 2002, 2016 Jens Keiner, Stefan Kunis, Daniel Potts
00003  *
00004  * This program is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU General Public License as published by the Free Software
00006  * Foundation; either version 2 of the License, or (at your option) any later
00007  * version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but WITHOUT
00010  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00012  * details.
00013  *
00014  * You should have received a copy of the GNU General Public License along with
00015  * this program; if not, write to the Free Software Foundation, Inc., 51
00016  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #include <stdio.h>
00020 #include <math.h>
00021 #include <string.h>
00022 #include <stdlib.h>
00023 #include <complex.h>
00024 
00025 #include "nfft3.h"
00026 #include "infft.h"
00027 #ifdef _OPENMP
00028 #include <omp.h>
00029 #endif
00030 
00031 void bench_openmp(FILE *infile, int m, int psi_flag)
00032 {
00033   NFFT(plan) p;
00034   int *N;
00035   int *n;
00036   int M, d, trafo_adjoint;
00037   int t, j;
00038   double re,im;
00039   ticks t0, t1;
00040   double tt_total, tt_preonepsi;
00041 
00042   fscanf(infile, "%d %d", &d, &trafo_adjoint);
00043 
00044   N = malloc(d*sizeof(int));
00045   n = malloc(d*sizeof(int));
00046 
00047   for (t=0; t<d; t++)
00048     fscanf(infile, "%d", N+t);
00049 
00050   for (t=0; t<d; t++)
00051     fscanf(infile, "%d", n+t);
00052 
00053   fscanf(infile, "%d", &M);
00054 
00055 #ifdef _OPENMP
00056   FFTW(import_wisdom_from_filename)("nfft_benchomp_detail_threads.plan");
00057 #else
00058   FFTW(import_wisdom_from_filename)("nfft_benchomp_detail_single.plan");
00059 #endif
00060 
00062   NFFT(init_guru)(&p, d, N, M, n, m,
00063                    PRE_PHI_HUT| psi_flag | MALLOC_X | MALLOC_F_HAT| MALLOC_F| FFTW_INIT | FFT_OUT_OF_PLACE,
00064                    FFTW_MEASURE| FFTW_DESTROY_INPUT);
00065 
00066 #ifdef _OPENMP
00067   FFTW(export_wisdom_to_filename)("nfft_benchomp_detail_threads.plan");
00068 #else
00069   FFTW(export_wisdom_to_filename)("nfft_benchomp_detail_single.plan");
00070 #endif
00071 
00072   for (j=0; j < p.M_total; j++)
00073   {
00074     for (t=0; t < p.d; t++)
00075       fscanf(infile, "%lg", p.x+p.d*j+t);
00076   }
00077 
00078   if (trafo_adjoint==0)
00079   {
00080     for (j=0; j < p.N_total; j++)
00081     {
00082       fscanf(infile, "%lg %lg", &re, &im);
00083       p.f_hat[j] = re + _Complex_I * im;
00084     }
00085   }
00086   else
00087   {
00088     for (j=0; j < p.M_total; j++)
00089     {
00090       fscanf(infile, "%lg %lg", &re, &im);
00091       p.f[j] = re + _Complex_I * im;
00092     }
00093   }
00094 
00095   t0 = getticks();
00097   if(p.flags & PRE_ONE_PSI)
00098       NFFT(precompute_one_psi)(&p);
00099   t1 = getticks();
00100   tt_preonepsi = NFFT(elapsed_seconds)(t1,t0);
00101 
00102   if (trafo_adjoint==0)
00103     NFFT(trafo)(&p);
00104   else
00105     NFFT(adjoint)(&p);
00106   t1 = getticks();
00107   tt_total = NFFT(elapsed_seconds)(t1,t0);
00108 
00109 #ifndef MEASURE_TIME
00110   p.MEASURE_TIME_t[0] = 0.0;
00111   p.MEASURE_TIME_t[2] = 0.0;
00112 #endif
00113 
00114 #ifndef MEASURE_TIME_FFTW
00115   p.MEASURE_TIME_t[1] = 0.0;
00116 #endif
00117 
00118   printf("%.6e %.6e %6e %.6e %.6e %.6e\n", tt_preonepsi, p.MEASURE_TIME_t[0], p.MEASURE_TIME_t[1], p.MEASURE_TIME_t[2], tt_total-tt_preonepsi-p.MEASURE_TIME_t[0]-p.MEASURE_TIME_t[1]-p.MEASURE_TIME_t[2], tt_total);
00119 //  printf("%.6e\n", tt);
00120 
00121   free(N);
00122   free(n);
00123 
00125   NFFT(finalize)(&p);
00126 }
00127 
00128 int main(int argc, char **argv)
00129 {
00130   int m, psi_flag;
00131 #ifdef _OPENMP
00132   int nthreads;
00133 
00134   if (argc != 4)
00135     return 1;
00136 
00137   nthreads = atoi(argv[3]);
00138   FFTW(init_threads)();
00139   omp_set_num_threads(nthreads);
00140 #else
00141   if (argc != 3)
00142     return 1;
00143 #endif
00144 
00145   m = atoi(argv[1]);
00146   psi_flag = atoi(argv[2]);
00147 
00148   bench_openmp(stdin, m, psi_flag);
00149 
00150   return 0;
00151 }