Partial commit of the project to remove all static variables.
[gromacs.git] / src / mdlib / timefft.c
blob9ed5f6b51bffab08b4ba9f6be3535b8b0e0300ac
1 /*
2 * $Id$
3 *
4 * This source code is part of
5 *
6 * G R O M A C S
7 *
8 * GROningen MAchine for Chemical Simulations
9 *
10 * VERSION 3.1
11 * Copyright (c) 1991-2001, University of Groningen, The Netherlands
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * If you want to redistribute modifications, please consider that
18 * scientific software is very special. Version control is crucial -
19 * bugs must be traceable. We will be happy to consider code for
20 * inclusion in the official distribution, but derived work must not
21 * be called official GROMACS. Details are found in the README & COPYING
22 * files - if they are missing, get the official version at www.gromacs.org.
24 * To help us fund GROMACS development, we humbly ask that you cite
25 * the papers on the package - you can find them in the top README file.
27 * For more info, check our website at http://www.gromacs.org
29 * And Hey:
30 * GROup of MAchos and Cynical Suckers
33 #include <math.h>
34 #include <stdio.h>
35 #include <time.h>
36 #include "typedefs.h"
37 #include "macros.h"
38 #include "smalloc.h"
39 #include "xvgr.h"
40 #include "complex.h"
41 #include "copyrite.h"
42 #include "fftgrid.h"
43 #include "mdrun.h"
44 #include "main.h"
45 #include "statutil.h"
47 int main(int argc,char *argv[])
49 int mmm[] = { 8, 10, 12, 15, 16, 18, 20, 24, 25, 27, 30, 32, 36, 40,
50 45, 48, 50, 54, 60, 64, 72, 75, 80, 81, 90, 100 };
51 int nnn[] = { 24, 32, 48, 60, 72, 84, 96 };
52 #define NNN asize(nnn)
53 FILE *fp;
54 int *niter;
55 int i,j,n,nit,ntot,n3,rsize;
56 double t,nflop,start;
57 double *rt,*ct;
58 t_fftgrid *g;
59 t_commrec *cr;
60 static bool bOptFFT = FALSE;
61 static int nnode = 1;
62 static int nitfac = 1;
63 t_pargs pa[] = {
64 { "-opt", FALSE, etBOOL, {&bOptFFT},
65 "Optimize FFT" },
66 { "-np", FALSE, etINT, {&nnode},
67 "Number of NODEs" },
68 { "-itfac", FALSE, etINT, {&nitfac},
69 "Multiply number of iterations by this" }
71 static t_filenm fnm[] = {
72 { efLOG, "-g", "fft", ffWRITE },
73 { efXVG, "-o", "fft", ffWRITE }
75 #define NFILE asize(fnm)
77 cr = init_par(&argc,&argv);
78 if (MASTER(cr))
79 CopyRight(stdout,argv[0]);
80 parse_common_args(&argc,argv,
81 PCA_CAN_SET_DEFFNM | (MASTER(cr) ? 0 : PCA_QUIET),
82 TRUE,NFILE,fnm,asize(pa),pa,0,NULL,0,NULL);
83 open_log(ftp2fn(efLOG,NFILE,fnm),cr);
85 snew(niter,NNN);
86 snew(ct,NNN);
87 snew(rt,NNN);
88 rsize = sizeof(real);
89 for(i=0; (i<NNN); i++) {
90 n = nnn[i];
91 if (n < 16)
92 niter[i] = 50;
93 else if (n < 26)
94 niter[i] = 20;
95 else if (n < 51)
96 niter[i] = 10;
97 else
98 niter[i] = 5;
99 niter[i] *= nitfac;
100 nit = niter[i];
102 if (MASTER(cr))
103 fprintf(stderr,"\r3D FFT (%s precision) %3d^3, niter %3d ",
104 (rsize == 8) ? "Double" : "Single",n,nit);
106 g = mk_fftgrid(stdlog,(nnode > 1),n,n,n,bOptFFT);
108 if (PAR(cr))
109 start = time(NULL);
110 else
111 start_time();
112 for(j=0; (j<nit); j++) {
113 gmxfft3D(g,FFTW_FORWARD,cr);
114 gmxfft3D(g,FFTW_BACKWARD,cr);
116 if (PAR(cr))
117 rt[i] = time(NULL)-start;
118 else {
119 update_time();
120 rt[i] = node_time();
122 done_fftgrid(g);
123 sfree(g);
125 if (MASTER(cr)) {
126 fprintf(stderr,"\n");
127 fp=xvgropen(ftp2fn(efXVG,NFILE,fnm),
128 "FFT timings","n^3","t (s)");
129 for(i=0; (i<NNN); i++) {
130 n3 = 2*niter[i]*nnn[i]*nnn[i]*nnn[i];
131 fprintf(fp,"%10d %10g\n",nnn[i],rt[i]/(2*niter[i]));
133 fclose(fp);
135 return 0;