vtf-logo

IndexGridData2.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 #ifndef _included_IndexGridData2_h
00004 #define _included_IndexGridData2_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_2
00027 #define for_2(i, j, r, s) {                                             \
00028    const int name2(j,_L) = (((r).lower(1)+((r).lower(1)<0?-s(1)+1:s(1)-1))/s(1))*s(1);     \
00029    const int name2(j,_U) = (r).upper(1);                                \
00030    const int name2(i,_L) = (((r).lower(0)+((r).lower(0)<0?-s(0)+1:s(0)-1))/s(0))*s(0);      \
00031    const int name2(i,_U) = (r).upper(0);                                \
00032    const int name2(sj,_S) = (s(1));                                     \
00033    const int name2(si,_S) = (s(0));                                     \
00034    for (register int j = name2(j,_L); j <= name2(j,_U); j+=name2(sj,_S))                \
00035    for (register int i = name2(i,_L); i <= name2(i,_U); i+=name2(si,_S)) {
00036 #endif
00037 
00038 #ifndef end_for
00039 #define end_for } }
00040 #endif
00041 
00042 /*
00043 *************************************************************************
00044 *                                                                       *
00045 * These macros provide simple access to ``fast indexing'' from C++.     *
00046 * Current C++ compilers do not do a good job of optimizing C++ loops    *
00047 * with array access.  Using these macros should speed up loops by a     *
00048 * factor of about three.  Note that we still use the Fortran indexing   *
00049 * convention.                                                           *
00050 *                                                                       *
00051 * These macros should be used as follows:                               *
00052 *                                                                       *
00053 *       BeginFastIndex2(a, double);                                     *
00054 *       for_2(i, j, a)                                                  *
00055 *          FastIndex2(a, i, j) = 0.0;                                   *
00056 *       end_for                                                         *
00057 *       EndFastIndex2(a);                                               *
00058 *                                                                       *
00059 *************************************************************************
00060 */
00061 
00062 #ifndef BeginFastIndex2
00063 #define BeginFastIndex2(a, b, d, type) {                                \
00064 const int   name2(a,_B)  = b.bottom();                                  \
00065 type *const name2(a,_D)  = d;                                           \
00066 const int   name2(a,_e0) = b.extents(0);                                \
00067 const int   name2(a,_s0) = b.stepsize(0);                               \
00068 const int   name2(a,_s1) = b.stepsize(1)
00069 #define FastIndex2(a, i, j)                                             \
00070 name2(a,_D)[name2(a,_B)+((i)/name2(a,_s0))+name2(a,_e0)*((j)/name2(a,_s1))]
00071 #define EndFastIndex2(a) }
00072 #endif
00073 
00074 #endif

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