Version bumps after new release
[alexxy/gromacs.git] / src / contrib / testfft.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  * GROningen Mixture of Alchemy and Childrens' Stories
34  */
35 #include <math.h>
36 #include <stdio.h>
37 #include "typedefs.h"
38 #include "macros.h"
39 #include "gromacs/utility/smalloc.h"
40 #include "xvgr.h"
41 #include "complex.h"
42 #include "fftgrid.h"
43 #include "mdrun.h"
44
45 void testfft(FILE *fp,t_complex ***grid,int nx,int ny,int nz,gmx_bool bFirst)
46 {
47 #ifdef USE_SGI_FFT
48 #ifdef GMX_DOUBLE
49   static    zomplex   *coeff;
50 #else
51   static    complex   *coeff;
52 #endif  
53   static    int la1,la2;
54 #endif
55   t_complex *cptr;
56   real      *gptr,*fqqq,fg,fac;
57   int       ntot,i,j,k,m,n,ndim[4];
58   int       npppm;
59   
60   ndim[0] = 0;
61   ndim[1] = nx;
62   ndim[2] = ny;
63   ndim[3] = nz;
64   
65   ntot    = nx*ny*nz;
66   cptr    = grid[0][0];
67   fqqq    = &(grid[0][0][0].re);
68   
69 #ifdef USE_SGI_FFT
70   if (bFirst) {
71     fprintf(fp,"Going to use SGI optimized FFT routines.\n");
72 #ifdef GMX_DOUBLE
73     coeff  = zfft3di(nx,ny,nz,NULL);
74 #else
75     coeff  = cfft3di(nx,ny,nz,NULL);
76 #endif
77     bFirst = FALSE;
78   }
79   la1 = nx;
80   la2 = ny;
81 #ifdef GMX_DOUBLE
82   zfft3d(1,nx,ny,nz,(zomplex *)cptr,la1,la2,coeff);
83 #else
84   cfft3d(1,nx,ny,nz,(complex *)cptr,la1,la2,coeff);
85 #endif
86 #else
87   fourn(fqqq-1,ndim,3,1);
88 #endif
89   
90 #ifdef USE_SGI_FFT
91 #ifdef GMX_DOUBLE
92   zfft3d(-1,nx,ny,nz,(zomplex *)cptr,la1,la2,coeff);
93 #else
94   cfft3d(-1,nx,ny,nz,(complex *)cptr,la1,la2,coeff);
95 #endif
96 #else
97   fourn(fqqq-1,ndim,3,-1);
98 #endif
99 }
100
101 void testrft(FILE *fp,real ***grid,int nx,int ny,int nz,gmx_bool bFirst)
102 {
103 #ifdef USE_SGI_FFT
104 #ifdef GMX_DOUBLE
105   static    double *coeff;
106 #else
107   static    float *coeff;
108 #endif
109   static    int la1,la2;
110 #endif
111   real      *cptr;
112   real      *gptr,*fqqq,fg,fac;
113   int       ntot,i,j,k,m,n,ndim[4];
114   int       npppm,job;
115   
116   ndim[0] = 0;
117   ndim[1] = nx;
118   ndim[2] = ny;
119   ndim[3] = nz;
120   
121   ntot    = nx*ny*nz;
122   cptr    = grid[0][0];
123   fqqq    = &(grid[0][0][0]);
124   
125 #ifdef USE_SGI_FFT
126   if (bFirst) {
127     fprintf(fp,"Going to use SGI optimized FFT routines.\n");
128 #ifdef GMX_DOUBLE
129     coeff  = dfft3di(nx,ny,nz,NULL);
130 #else
131     coeff  = sfft3di(nx,ny,nz,NULL);
132 #endif
133     bFirst = FALSE;
134   }
135   job = 1;
136   la1 = nx+2;
137   la2 = ny;
138 #ifdef GMX_DOUBLE
139   dzfft3d(job,nx,ny,nz,cptr,la1,la2,coeff);
140 #else
141   scfft3d(job,nx,ny,nz,cptr,la1,la2,coeff);
142 #endif
143 #else
144   fourn(fqqq-1,ndim,3,1);
145 #endif
146
147   job = -1;
148   
149 #ifdef USE_SGI_FFT
150 #ifdef GMX_DOUBLE
151   zdfft3d(job,nx,ny,nz,cptr,la1,la2,coeff);
152 #else
153   csfft3d(job,nx,ny,nz,cptr,la1,la2,coeff);
154 #endif
155 #else
156   fourn(fqqq-1,ndim,3,-1);
157 #endif
158 }
159
160 int main(int argc,char *argv[])
161 {
162   FILE      *fp;
163   int       nnn[] = { 8, 10, 12, 15, 16, 18, 20, 24, 25, 27, 30, 32, 36, 40,
164                       45, 48, 50, 54, 60, 64, 72, 75, 80, 81, 90, 100 };
165 #define NNN asize(nnn)
166   int       *niter;
167   int       i,j,n,nit,ntot,n3;
168   double    t,nflop;
169   double    *rt,*ct;
170   t_complex ***g;
171   real      ***h;
172   
173   snew(rt,NNN);
174   snew(ct,NNN);
175   snew(niter,NNN);
176   
177   for(i=0; (i<NNN); i++) {
178     n = nnn[i];
179     fprintf(stderr,"\rReal %d     ",n);
180     if (n < 16)
181       niter[i] = 100;
182     else if (n < 26)
183       niter[i] = 50;
184     else if (n < 51)
185       niter[i] = 10;
186     else
187       niter[i] = 5;
188     nit = niter[i];
189       
190     h   = mk_rgrid(n+2,n,n);
191     start_time();
192     for(j=0; (j<nit); j++) {
193       testrft(stdout,h,n,n,n,(j==0));
194     }
195     update_time();
196     rt[i] = node_time();
197     free_rgrid(h,n,n);
198     
199     fprintf(stderr,"\rComplex %d     ",n);
200     g   = mk_cgrid(n,n,n);
201     start_time();
202     for(j=0; (j<nit); j++) {
203       testfft(stdout,g,n,n,n,(j==0));
204     }
205     update_time();
206     ct[i] = node_time();
207     free_cgrid(g,n,n);
208   }
209   fprintf(stderr,"\n");
210   fp=xvgropen("timing.xvg","FFT timings per grid point","n","t (s)");
211   for(i=0; (i<NNN); i++) {
212     n3 = 2*niter[i]*nnn[i]*nnn[i]*nnn[i];
213     fprintf(fp,"%10d  %10g  %10g\n",nnn[i],rt[i]/n3,ct[i]/n3);
214   }
215   gmx_fio_fclose(fp);
216   
217   return 0;
218 }