Merge branch release-4-6 into release-5-0
[alexxy/gromacs.git] / src / contrib / timefft.c
1 /*
2  * 
3  *                This source code is part of
4  * 
5  *                 G   R   O   M   A   C   S
6  * 
7  *          GROningen MAchine for Chemical Simulations
8  * 
9  *                        VERSION 3.2.0
10  * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12  * Copyright (c) 2001-2004, The GROMACS development team,
13  * check out http://www.gromacs.org for more information.
14
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  * 
20  * If you want to redistribute modifications, please consider that
21  * scientific software is very special. Version control is crucial -
22  * bugs must be traceable. We will be happy to consider code for
23  * inclusion in the official distribution, but derived work must not
24  * be called official GROMACS. Details are found in the README & COPYING
25  * files - if they are missing, get the official version at www.gromacs.org.
26  * 
27  * To help us fund GROMACS development, we humbly ask that you cite
28  * the papers on the package - you can find them in the top README file.
29  * 
30  * For more info, check our website at http://www.gromacs.org
31  * 
32  * And Hey:
33  * GROwing Monsters And Cloning Shrimps
34  */
35 #include <math.h>
36 #include <stdio.h>
37 #include <time.h>
38
39 #include "typedefs.h"
40 #include "macros.h"
41 #include "gromacs/utility/smalloc.h"
42 #include "xvgr.h"
43 #include "copyrite.h"
44 #include "mdrun.h"
45 #include "main.h"
46 #include "gromacs/commandline/pargs.h"
47 #include "gromacs/fft/fft.h"
48 #include "gromacs/math/gmxcomplex.h"
49
50 #ifdef GMX_MPI
51 #include "gromacs/fft/parallel_3dfft.h"
52 #endif
53
54 #include "fftgrid.h"
55
56
57 int main(int argc,char *argv[])
58 {
59   int       mmm[] = { 8, 10, 12, 15, 16, 18, 20, 24, 25, 27, 30, 32, 36, 40,
60                       45, 48, 50, 54, 60, 64, 72, 75, 80, 81, 90, 100 };
61   int       nnn[] = { 24, 32, 48, 60, 72, 84, 96 };
62 #define NNN asize(nnn)
63   FILE      *fp,*fplog;
64   int       *niter;
65   int       i,j,n,nit,ntot,n3,rsize;
66   double    t,nflop,start;
67   double    *rt,*ct;
68   t_fftgrid *g;
69   t_commrec *cr;
70   static gmx_bool bReproducible = FALSE;
71   static int  nnode    = 1;
72   static int  nitfac  = 1;
73   t_pargs pa[] = {
74     { "-reproducible",   FALSE, etBOOL, {&bReproducible}, 
75       "Request binary reproducible results" },
76     { "-np",    FALSE, etINT, {&nnode},
77       "Number of NODEs" },
78     { "-itfac", FALSE, etINT, {&nitfac},
79       "Multiply number of iterations by this" }
80   };
81   static t_filenm fnm[] = {
82     { efLOG, "-g", "fft",      ffWRITE },
83     { efXVG, "-o", "fft",      ffWRITE }
84   };
85 #define NFILE asize(fnm)
86   
87   cr = init_par(&argc,&argv);
88   if (MASTER(cr))
89     CopyRight(stdout,argv[0]);
90   parse_common_args(&argc,argv,
91                     PCA_CAN_SET_DEFFNM | (MASTER(cr) ? 0 : PCA_QUIET),
92                     NFILE,fnm,asize(pa),pa,0,NULL,0,NULL);
93   gmx_log_open(ftp2fn(efLOG,NFILE,fnm),cr,1,0,&fplog);
94
95   snew(niter,NNN);
96   snew(ct,NNN);
97   snew(rt,NNN);
98   rsize = sizeof(real);
99   for(i=0; (i<NNN); i++) {
100     n  = nnn[i];
101     if (n < 16)
102       niter[i] = 50;
103     else if (n < 26)
104       niter[i] = 20;
105     else if (n < 51)
106       niter[i] = 10;
107     else
108       niter[i] = 5;
109     niter[i] *= nitfac;
110     nit = niter[i];
111     
112     if (MASTER(cr))
113       fprintf(stderr,"\r3D FFT (%s precision) %3d^3, niter %3d     ",
114               (rsize == 8) ? "Double" : "Single",n,nit);
115     
116     g  = mk_fftgrid(n,n,n,NULL,NULL,cr,bReproducible);
117
118     if (PAR(cr))
119       start = time(NULL);
120     else
121       start_time();
122     for(j=0; (j<nit); j++) {
123       gmxfft3D(g,GMX_FFT_REAL_TO_COMPLEX,cr);
124       gmxfft3D(g,GMX_FFT_COMPLEX_TO_REAL,cr);
125     }
126     if (PAR(cr)) 
127       rt[i] = time(NULL)-start;
128     else {
129       update_time();
130       rt[i] = node_time();
131     }
132     done_fftgrid(g);
133     sfree(g);
134   }
135   if (MASTER(cr)) {
136     fprintf(stderr,"\n");
137     fp=xvgropen(ftp2fn(efXVG,NFILE,fnm),
138                 "FFT timings","n^3","t (s)");
139     for(i=0; (i<NNN); i++) {
140       n3 = 2*niter[i]*nnn[i]*nnn[i]*nnn[i];
141       fprintf(fp,"%10d  %10g\n",nnn[i],rt[i]/(2*niter[i]));
142     }
143     gmx_fio_fclose(fp);
144   }
145   return 0;
146 }