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