Fix compile error for IBM VMX on ppc64
[gromacs/AngularHB.git] / src / contrib / testfft.c
blob1f2f4936ac1fb2ea590c9e78a4bb543108145f59
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.
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.
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.
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.
30 * For more info, check our website at http://www.gromacs.org
32 * And Hey:
33 * GROningen Mixture of Alchemy and Childrens' Stories
35 #include <math.h>
36 #include <stdio.h>
37 #include "typedefs.h"
38 #include "macros.h"
39 #include "gromacs/utility/smalloc.h"
40 #include "gromacs/fileio/xvgr.h"
41 #include "complex.h"
42 #include "fftgrid.h"
43 #include "mdrun.h"
45 void testfft(FILE *fp,t_complex ***grid,int nx,int ny,int nz,gmx_bool bFirst)
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;
60 ndim[0] = 0;
61 ndim[1] = nx;
62 ndim[2] = ny;
63 ndim[3] = nz;
65 ntot = nx*ny*nz;
66 cptr = grid[0][0];
67 fqqq = &(grid[0][0][0].re);
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;
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
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
101 void testrft(FILE *fp,real ***grid,int nx,int ny,int nz,gmx_bool bFirst)
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;
116 ndim[0] = 0;
117 ndim[1] = nx;
118 ndim[2] = ny;
119 ndim[3] = nz;
121 ntot = nx*ny*nz;
122 cptr = grid[0][0];
123 fqqq = &(grid[0][0][0]);
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;
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
147 job = -1;
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
160 int main(int argc,char *argv[])
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;
173 snew(rt,NNN);
174 snew(ct,NNN);
175 snew(niter,NNN);
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];
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));
195 update_time();
196 rt[i] = node_time();
197 free_rgrid(h,n,n);
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));
205 update_time();
206 ct[i] = node_time();
207 free_cgrid(g,n,n);
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);
215 gmx_fio_fclose(fp);
217 return 0;