vtf-logo

IndexGridData3.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 #ifndef _included_IndexGridData3_h
00004 #define _included_IndexGridData3_h
00005 
00012 #include "generic.h"
00013 
00014 /*
00015 *************************************************************************
00016 *                                                                       *
00017 * Define some looping constructs for GridData.  Note that these will    *
00018 * take either an array or a region as the second argument.              *
00019 *                                                                       *
00020 * Copy the region extents into a local constant integer to aid the      *
00021 * compiler in doing some loop optimizations.                            *
00022 *                                                                       *
00023 *************************************************************************
00024 */
00025 
00026 #ifndef for_3
00027 #define for_3(i, j, k, r, s) {                                          \
00028    const int name2(k,_L) = (((r).lower(2)+((r).lower(2)<0?-s(2)+1:s(2)-1))/s(2))*s(2);    \
00029    const int name2(k,_U) = (r).upper(2);                                \
00030    const int name2(j,_L) = (((r).lower(1)+((r).lower(1)<0?-s(1)+1:s(1)-1))/s(1))*s(1);    \
00031    const int name2(j,_U) = (r).upper(1);                                \
00032    const int name2(i,_L) = (((r).lower(0)+((r).lower(0)<0?-s(0)+1:s(0)-1))/s(0))*s(0);    \
00033    const int name2(i,_U) = (r).upper(0);                                \
00034    const int name2(sk,_S) = (s(2));                                     \
00035    const int name2(sj,_S) = (s(1));                                     \
00036    const int name2(si,_S) = (s(0));                                     \
00037    for (register int k = name2(k,_L); k <= name2(k,_U); k+=name2(sk,_S))                \
00038    for (register int j = name2(j,_L); j <= name2(j,_U); j+=name2(sj,_S))                \
00039    for (register int i = name2(i,_L); i <= name2(i,_U); i+=name2(si,_S)) {
00040 #endif
00041 
00042 #ifndef end_for
00043 #define end_for } }
00044 #endif
00045 
00046 /*
00047 *************************************************************************
00048 *                                                                       *
00049 * These macros provide simple access to ``fast indexing'' from C++.     *
00050 * Current C++ compilers do not do a good job of optimizing C++ loops    *
00051 * with array access.  Using these macros should speed up loops by a     *
00052 * factor of about three.  Note that we still use the Fortran indexing   *
00053 * convention.                                                           *
00054 *                                                                       *
00055 * These macros should be used as follows:                               *
00056 *                                                                       *
00057 *       BeginFastIndex2(a, double);                                     *
00058 *       for_2(i, j, a)                                                  *
00059 *          FastIndex2(a, i, j) = 0.0;                                   *
00060 *       end_for                                                         *
00061 *       EndFastIndex2(a);                                               *
00062 *                                                                       *
00063 *************************************************************************
00064 */
00065 
00066 
00067 
00068 #ifndef BeginFastIndex3
00069 #define BeginFastIndex3(a, b, d, type) {                                \
00070 const int   name2(a,_B)  = b.bottom();                                  \
00071 type *const name2(a,_D)  = d;                                           \
00072 const int   name2(a,_e0) = b.extents(0);                                \
00073 const int   name2(a,_e1) = b.extents(1);                                \
00074 const int   name2(a,_s0) = b.stepsize(0);                               \
00075 const int   name2(a,_s1) = b.stepsize(1);                               \
00076 const int   name2(a,_s2) = b.stepsize(2)
00077 #define FastIndex3(a, i, j, k)                                          \
00078 name2(a,_D)[name2(a,_B)+((i)/name2(a,_s0))+name2(a,_e0)*(((j)/name2(a,_s1))+name2(a,_e1)*((k)/name2(a,_s2)))]
00079 #define EndFastIndex3(a) }
00080 #endif
00081 
00082 #endif

Generated on Fri Aug 24 13:00:29 2007 for AMROC's Hierachical Data Structures - by  doxygen 1.4.7