1 #include "mrilib.h"
2
3 #define ASSIGN_DIRECTIONS \
4 do{ switch( fixdir ){ \
5 default: \
6 case 1: /* x-direction: (a,b,c) = (y,z,x) */ \
7 astep = nx ; bstep = nxy ; cstep = 1 ; \
8 na = ny ; nb = nz ; nc = nx ; \
9 break ; \
10 \
11 case 2: /* y-direction: (a,b,c) = (z,x,y) */ \
12 astep = nxy ; bstep = 1 ; cstep = nx ; \
13 na = nz ; nb = nx ; nc = ny ; \
14 break ; \
15 \
16 case 3: /* z-direction: (a,b,c) = (x,y,z) */ \
17 astep = 1 ; bstep = nx ; cstep = nxy ; \
18 na = nx ; nb = ny ; nc = nz ; \
19 break ; \
20 } } while(0)
21
22 /*-----------------------------------------------------------------------
23 Simple get/put of a fixed plane (no shifting, zero padding).
24 -------------------------------------------------------------------------*/
25
getplane_byte(int nx,int ny,int nz,byte * vol,int fixdir,int fixijk,byte * im)26 void getplane_byte( int nx , int ny , int nz , byte * vol ,
27 int fixdir , int fixijk , byte * im )
28 {
29 int bb , nxy=nx*ny ;
30 register int aa , ijkoff , aoff,boff ;
31 int astep,bstep,cstep , na,nb,nc ;
32
33 if( fixijk < 0 ) return ;
34
35 ASSIGN_DIRECTIONS ;
36
37 if( fixijk >= nc ) return ;
38
39 ijkoff = fixijk*cstep ;
40
41 for( bb=0,boff=0 ; bb < nb ; bb++,boff+=na,ijkoff+=bstep )
42 for( aa=0,aoff=0 ; aa < na ; aa++,aoff+=astep )
43 im[aa+boff] = vol[aoff+ijkoff] ;
44
45 return ;
46 }
47
putplane_byte(int nx,int ny,int nz,byte * vol,int fixdir,int fixijk,byte * im)48 void putplane_byte( int nx , int ny , int nz , byte * vol ,
49 int fixdir , int fixijk , byte * im )
50 {
51 int bb , nxy=nx*ny ;
52 register int aa , ijkoff , aoff,boff ;
53 int astep,bstep,cstep , na,nb,nc ;
54
55 if( fixijk < 0 ) return ;
56
57 ASSIGN_DIRECTIONS ;
58
59 if( fixijk >= nc ) return ;
60
61 ijkoff = fixijk*cstep ;
62
63 for( bb=0,boff=0 ; bb < nb ; bb++,boff+=na,ijkoff+=bstep )
64 for( aa=0,aoff=0 ; aa < na ; aa++,aoff+=astep )
65 vol[aoff+ijkoff] = im[aa+boff] ;
66
67 return ;
68 }
69
swaptest(int nrep,int fixdir)70 void swaptest( int nrep , int fixdir )
71 {
72 double cputim ;
73 int pp , nx=100,ny=100,nz=100,nxy=nx*ny , kk ;
74 byte * vin , * vout ;
75 int astep,bstep,cstep , na,nb,nc ;
76
77 if( nrep <= 0 ) nrep = 1 ;
78
79 ASSIGN_DIRECTIONS ;
80
81 /* setup bricks */
82
83 vin = (byte *) malloc( sizeof(byte) * (nx*ny*nz) ) ;
84 if( vin == NULL ) return ;
85
86 vout = (byte *) malloc( sizeof(byte) * (na*nb*nc) ) ;
87 if( vout == NULL ){ free(vin) ; return ; }
88
89 for( kk=0 ; kk < nx*ny*nz ; kk++ ) vin[kk] = (byte) kk ;
90
91 cputim = COX_cpu_time() ;
92
93 for( pp=0 ; pp < nrep ; pp++ ){
94 #if 0
95 for( kk=0 ; kk < nc ; kk++ ){
96 getplane_byte( nx,ny,nz , vin , fixdir , kk , vout + kk*na*nb ) ;
97 }
98 #else
99 for( kk=0 ; kk < nz ; kk++ ){
100 putplane_byte( nx,ny,nz , vout , fixdir , kk , vin + kk*nx*ny ) ;
101 }
102 #endif
103 }
104 cputim = COX_cpu_time() - cputim ;
105 printf("fixdir = %d CPU time = %g (%g/rep)\n",fixdir,cputim,cputim/nrep) ;
106 return ;
107 }
108
main(int argc,char * argv[])109 int main( int argc , char * argv[] )
110 {
111 int nrep ;
112
113 if( argc < 2 ){printf("Usage: exx nrep\n");exit(0);}
114
115 nrep = strtol(argv[1],NULL,10) ;
116 swaptest( nrep , 1 ) ;
117 swaptest( nrep , 2 ) ;
118 swaptest( nrep , 3 ) ;
119 exit(0) ;
120 }
121