dump.cc 4.66 KB
Newer Older
thomas.forbriger's avatar
thomas.forbriger committed
1
2
3
4
5
/*! \file dump.cc
 * \brief debug helpers (implementation)
 * 
 * ----------------------------------------------------------------------------
 * 
thomas.forbriger's avatar
thomas.forbriger committed
6
 * $Id: dump.cc,v 1.9 2006/03/28 16:03:02 tforb Exp $
thomas.forbriger's avatar
thomas.forbriger committed
7
8
9
10
 * \author Thomas Forbriger
 * \date 12/12/2002
 * 
 * debug helpers (implementation)
thomas.forbriger's avatar
thomas.forbriger committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 *
 * ----
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version. 
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 * ----
 *
thomas.forbriger's avatar
thomas.forbriger committed
28
29
 * \sa group_helpers
 *
thomas.forbriger's avatar
thomas.forbriger committed
30
31
32
33
 * Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt) 
 * 
 * REVISIONS and CHANGES 
 *  - 12/12/2002   V1.0   Thomas Forbriger
thomas.forbriger's avatar
thomas.forbriger committed
34
35
 *  - 18/12/2002   V1.1   (thof)
 *                        - stated definitions
36
37
 *  - 29/12/2002   V1.2   (thof)
 *                        - include only those headers we need
thomas.forbriger's avatar
thomas.forbriger committed
38
39
40
41
 * 
 * ============================================================================
 */
#define AFF_DUMP_CC_VERSION \
thomas.forbriger's avatar
thomas.forbriger committed
42
43
  "AFF_DUMP_CC   V1.1"
#define AFF_DUMP_CC_CVSID \
thomas.forbriger's avatar
thomas.forbriger committed
44
  "$Id: dump.cc,v 1.9 2006/03/28 16:03:02 tforb Exp $"
thomas.forbriger's avatar
thomas.forbriger committed
45

46
47
#include <aff/lib/dump_strided.h>
#include <aff/lib/error.h>
thomas.forbriger's avatar
thomas.forbriger committed
48
49
50

namespace aff {

thomas.forbriger's avatar
thomas.forbriger committed
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! dump shape
void dump(const Strided& shape, std::ostream& os)
{
  os << "dump of a Strided object:" << endl;
  os << "  index ranges: ";
  for (Tsize i=0; i<Strided::Mmax_dimen; i++)
  {
    os << "[" << shape.first(i) << ":" << shape.last(i) << "]";
  }
  os << endl;
  os << "  strides: ";
  for (Tsize i=0; i<Strided::Mmax_dimen; i++)
  {
    if (i>0) os << ", ";
    os << shape.stride(i);
  }
  os << endl;
  os << "  total number of mapped elements: "
    << shape.size() << endl;
  os << "  total address range in memory: ["
    << shape.first_offset() << ":" << shape.last_offset() << "] = "
    << shape.memory_size() << " positions" << endl;
}

/*----------------------------------------------------------------------*/

77
78
namespace {

thomas.forbriger's avatar
thomas.forbriger committed
79
80
81
82
  /*! \brief recursive usage tests all offset functions
   *
   * \ingroup group_helpers
   */
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
  void dump_map_helper(const Strided& shape, const Tdim& i, const Tdim& j,
                  Strided::TIndexVec& index, std::ostream& os)
  {
    if (i>1)
    {
      for (index[i]=shape.first(i); index[i]<=shape.last(i); index[i]++)
      {
        os << "    dimension "; 
        os << i << ": [" << index[i] << "]";
        dump_map_helper(shape, i-1, j, index, os);
      }
    }
    else if (i>0)
    {
      if (i<j) os << endl;
thomas.forbriger's avatar
thomas.forbriger committed
98
      os.width(5); os << " ";
99
100
      for (int k=shape.first(1); k<=shape.last(1); k++)
      {
thomas.forbriger's avatar
thomas.forbriger committed
101
        os.width(6); os << k;
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
      }
      os << endl;
      for (index[0]=shape.first(0); index[0]<=shape.last(0); index[0]++)
      {
        os.width(5); os << index[0];
        for (index[1]=shape.first(1); index[1]<=shape.last(1); index[1]++)
        {
          os.width(5); 
          if (j==0)
          { os << shape.offset(index[0]); }
          else if (j==1)
          { os << shape.offset(index[0], index[1]); }
          else if (j==2)
          { os << shape.offset(index[0], index[1], index[2]); }
          else if (j==3)
          { os << shape.offset(index[0], index[1], index[2], index[3]); }
          else 
          { os << shape.offset(index); }
          os << "#";
        }
        os << endl;
      }
    }
    else 
    {
      for (index[0]=shape.first(0); index[0]<=shape.last(0); index[0]++)
      {
        os.width(5); os << index[0];
        os.width(5); 
        if (j==0)
        { os << shape.offset(index[0]); }
        else if (j==1)
        { os << shape.offset(index[0], index[1]); }
        else if (j==2)
        { os << shape.offset(index[0], index[1], index[2]); }
        else if (j==3)
        { os << shape.offset(index[0], index[1], index[2], index[3]); }
        else 
        { os << shape.offset(index); }
        os << "#" << endl;
      }
    }
  }
thomas.forbriger's avatar
thomas.forbriger committed
145
}
146

thomas.forbriger's avatar
thomas.forbriger committed
147
//! dump index mapping of shape
148
void dump_map(const Strided& shape, const Tdim& i, std::ostream& os)
thomas.forbriger's avatar
thomas.forbriger committed
149
{
150
151
  AFF_assert((i<Strided::Mmax_dimen),
             "ERROR (dump_map): illegal dimensionality");
thomas.forbriger's avatar
thomas.forbriger committed
152
  dump(shape);
153
  os << "  index mapping for " << i+1 << " dimensional access:" << endl;
154
155
  Strided::TIndexVec index(shape.first());
  dump_map_helper(shape, i, i, index, os); 
thomas.forbriger's avatar
thomas.forbriger committed
156
157
}

thomas.forbriger's avatar
thomas.forbriger committed
158
159
160
} // namespace aff

/* ----- END OF dump.cc ----- */