/usr/include/blitz/array/storage.h is in libblitz0-dev 1:0.10-3.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 | // -*- C++ -*-
/***************************************************************************
* blitz/array/storage.h Memory layout of Arrays.
*
* $Id$
*
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
*
* This file is a part of Blitz.
*
* Blitz is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Blitz 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
*
* Suggestions: blitz-devel@lists.sourceforge.net
* Bugs: blitz-support@lists.sourceforge.net
*
* For more information, please see the Blitz++ Home Page:
* https://sourceforge.net/projects/blitz/
*
****************************************************************************/
#ifndef BZ_ARRAY_STORAGE_H
#define BZ_ARRAY_STORAGE_H
#ifdef BZ_HAVE_BOOST_SERIALIZATION
#include <boost/serialization/serialization.hpp>
#endif
#ifdef BZ_HAVE_BOOST_MPI
#include <boost/mpi/datatype.hpp>
#endif
BZ_NAMESPACE(blitz)
/// Enum for specifying whether padding for alignment should be done.
enum paddingPolicy {
/// The container should have contiguous data.
contiguousData,
/** The container data should be padded so minor rank dimensions
always are SIMD aligned. */
paddedData
};
/** The default padding policy, set by the configure script
--enable-array-length-padding argument. */
const paddingPolicy defaultPadding = BZ_PADDING_DEFAULT;
/**
Declaration of class GeneralArrayStorage<N_rank>
This class describes a storage format for an N-dimensional array.
The dimensions can be stored in an arbitrary order (for example, as
a C-style row major array or Fortran-style column major array, or
something else entirely). Each dimension can be stored in either
ascending (the most common) or descending order. Each dimension can
have its own base (starting index value: e.g. 0 for C-style arrays,
1 for Fortran arrays). The GeneralArrayStorage class also
determines the padding policy when SIMD width is set.
GeneralArrayStorage<N> defaults to C-style arrays. To implement
other storage formats, subclass and modify the constructor. The
class FortranArray, below, is an example.
Objects inheriting from GeneralArrayStorage<N> can be passed as
an optional constructor argument to Array objects.
e.g. Array<int,3> A(16,16,16, FortranArray<3>());
will create a 3-dimensional 16x16x16 Fortran-style array.
*/
template<int N_rank>
class GeneralArrayStorage {
public:
class noInitializeFlag { };
GeneralArrayStorage(noInitializeFlag)
{ }
GeneralArrayStorage(paddingPolicy pp = defaultPadding)
{
for (int i=0; i < N_rank; ++i)
ordering_(i) = N_rank - 1 - i;
ascendingFlag_ = true;
base_ = 0;
paddingPolicy_ = pp;
}
GeneralArrayStorage(const GeneralArrayStorage<N_rank>& x)
: paddingPolicy_(x.paddingPolicy_), ascendingFlag_(x.ascendingFlag_),
ordering_(x.ordering_), base_(x.base_)
{
}
GeneralArrayStorage(TinyVector<int,N_rank> ordering,
TinyVector<bool,N_rank> ascendingFlag,
paddingPolicy pp = defaultPadding)
: paddingPolicy_(pp), ascendingFlag_(ascendingFlag),
ordering_(ordering)
{
base_ = 0;
}
~GeneralArrayStorage()
{ }
GeneralArrayStorage<N_rank>& operator=(
const GeneralArrayStorage<N_rank>& rhs)
{
ordering_ = rhs.ordering();
ascendingFlag_ = rhs.ascendingFlag();
base_ = rhs.base();
paddingPolicy_ = rhs.paddingPolicy_;
return *this;
}
TinyVector<int, N_rank>& ordering()
{ return ordering_; }
const TinyVector<int, N_rank>& ordering() const
{ return ordering_; }
int ordering(int i) const
{ return ordering_[i]; }
void setOrdering(int i, int order)
{ ordering_[i] = order; }
bool allRanksStoredAscending() const
{
for (int i=0; i < N_rank; ++i)
if (!ascendingFlag_[i]) return false;
return true;
}
bool isRankStoredAscending(int i) const
{ return ascendingFlag_[i]; }
TinyVector<bool, N_rank>& ascendingFlag()
{ return ascendingFlag_; }
const TinyVector<bool, N_rank>& ascendingFlag() const
{ return ascendingFlag_; }
void setAscendingFlag(int i, bool ascendingFlag)
{ ascendingFlag_[i] = ascendingFlag; }
TinyVector<int, N_rank>& base()
{ return base_; }
const TinyVector<int, N_rank>& base() const
{ return base_; }
int base(int i) const
{ return base_[i]; }
void setBase(int i, int base)
{ base_[i] = base; }
void setBase(const TinyVector<int, N_rank>& base)
{ base_ = base; }
const paddingPolicy& padding() const { return paddingPolicy_; }
private:
#ifdef BZ_HAVE_BOOST_SERIALIZATION
friend class boost::serialization::access;
template<class T_arch>
void serialize(T_arch& ar, const unsigned int version) {
ar & paddingPolicy_;
ar & ascendingFlag_;
ar & ordering_;
ar & base_;
};
#endif
protected:
/*
* ordering_[] specifies the order in which the array is stored in
* memory. For a newly allocated array, ordering_(0) will give the
* rank with unit stride, and ordering_(N_rank-1) will be the rank
* with largest stride. An order like [2, 1, 0] corresponds to
* C-style array storage; an order like [0, 1, 2] corresponds to
* Fortran array storage.
*
* ascendingFlag_[] indicates whether the data in a rank is stored
* in ascending or descending order. Most of the time these values
* will all be true (indicating ascending order). Some peculiar
* formats (e.g. MS-Windows BMP image format) store the data in
* descending order.
*
* base_[] gives the first valid index for each rank. For a C-style
* array, all the base_ elements will be zero; for a Fortran-style
* array, they will be one. base_[] can be set arbitrarily using
* the Array constructor which takes a Range argument, e.g.
* Array<float,2> A(Range(30,40),Range(23,33));
* will create an array with base_[] = { 30, 23 }.
*/
// declare the tinyvector<bool> first, because it doesn't have alignment
paddingPolicy paddingPolicy_;
TinyVector<bool, N_rank> ascendingFlag_;
TinyVector<int, N_rank> ordering_;
TinyVector<int, N_rank> base_;
};
/** This tag class can be used to provide a nicer notation for
constructing padded arrays: instead of
Array<int,2> A(3, 3, GeneralArrayStorage<2>(paddedData));
one can simply write:
Array<int,2> A(3, 3, paddedArray);
where paddedArray is an object of type _bz_paddedTag.
*/
class _bz_paddedTag {
public:
operator GeneralArrayStorage<1>()
{ return GeneralArrayStorage<1>(paddedData); }
operator GeneralArrayStorage<2>()
{ return GeneralArrayStorage<2>(paddedData); }
operator GeneralArrayStorage<3>()
{ return GeneralArrayStorage<3>(paddedData); }
operator GeneralArrayStorage<4>()
{ return GeneralArrayStorage<4>(paddedData); }
operator GeneralArrayStorage<5>()
{ return GeneralArrayStorage<5>(paddedData); }
operator GeneralArrayStorage<6>()
{ return GeneralArrayStorage<6>(paddedData); }
operator GeneralArrayStorage<7>()
{ return GeneralArrayStorage<7>(paddedData); }
operator GeneralArrayStorage<8>()
{ return GeneralArrayStorage<8>(paddedData); }
operator GeneralArrayStorage<9>()
{ return GeneralArrayStorage<9>(paddedData); }
operator GeneralArrayStorage<10>()
{ return GeneralArrayStorage<10>(paddedData); }
operator GeneralArrayStorage<11>()
{ return GeneralArrayStorage<11>(paddedData); }
};
// A global instance of this class will be placed in
// the blitz library (libblitz.a on unix machines).
_bz_global _bz_paddedTag paddedArray;
/** This tag class can be used to provide a nicer notation for
constructing unpadded arrays: instead of
Array<int,2> A(3, 3, GeneralArrayStorage<2>(contiguousData));
one can simply write:
Array<int,2> A(3, 3, contiguousArray);
where contiguousArray is an object of type _bz_contiguousTag.
*/
class _bz_contiguousTag {
public:
operator GeneralArrayStorage<1>()
{ return GeneralArrayStorage<1>(contiguousData); }
operator GeneralArrayStorage<2>()
{ return GeneralArrayStorage<2>(contiguousData); }
operator GeneralArrayStorage<3>()
{ return GeneralArrayStorage<3>(contiguousData); }
operator GeneralArrayStorage<4>()
{ return GeneralArrayStorage<4>(contiguousData); }
operator GeneralArrayStorage<5>()
{ return GeneralArrayStorage<5>(contiguousData); }
operator GeneralArrayStorage<6>()
{ return GeneralArrayStorage<6>(contiguousData); }
operator GeneralArrayStorage<7>()
{ return GeneralArrayStorage<7>(contiguousData); }
operator GeneralArrayStorage<8>()
{ return GeneralArrayStorage<8>(contiguousData); }
operator GeneralArrayStorage<9>()
{ return GeneralArrayStorage<9>(contiguousData); }
operator GeneralArrayStorage<10>()
{ return GeneralArrayStorage<10>(contiguousData); }
operator GeneralArrayStorage<11>()
{ return GeneralArrayStorage<11>(contiguousData); }
};
// A global instance of this class will be placed in
// the blitz library (libblitz.a on unix machines).
_bz_global _bz_contiguousTag contiguousArray;
/**
Class FortranArray specializes GeneralArrayStorage to provide
Fortran style arrays (column major ordering, base of 1). The
noInitializeFlag() passed to the base constructor indicates that
the subclass will take care of initializing the ordering_,
ascendingFlag_ and base_ members.
*/
template<int N_rank>
class FortranArray : public GeneralArrayStorage<N_rank> {
private:
typedef GeneralArrayStorage<N_rank> T_base;
typedef _bz_typename T_base::noInitializeFlag noInitializeFlag;
using T_base::ordering_;
using T_base::ascendingFlag_;
using T_base::base_;
using T_base::paddingPolicy_;
public:
FortranArray(paddingPolicy pp = defaultPadding)
: GeneralArrayStorage<N_rank>(noInitializeFlag())
{
for (int i=0; i < N_rank; ++i)
ordering_(i) = i;
ascendingFlag_ = true;
base_ = 1;
paddingPolicy_ = pp;
}
};
// This tag class can be used to provide a nicer notation for
// constructing Fortran-style arrays: instead of
// Array<int,2> A(3, 3, FortranArray<2>());
// one can simply write:
// Array<int,2> A(3, 3, fortranArray);
// where fortranArray is an object of type _bz_fortranTag.
class _bz_fortranTag {
public:
operator GeneralArrayStorage<1>()
{ return FortranArray<1>(); }
operator GeneralArrayStorage<2>()
{ return FortranArray<2>(); }
operator GeneralArrayStorage<3>()
{ return FortranArray<3>(); }
operator GeneralArrayStorage<4>()
{ return FortranArray<4>(); }
operator GeneralArrayStorage<5>()
{ return FortranArray<5>(); }
operator GeneralArrayStorage<6>()
{ return FortranArray<6>(); }
operator GeneralArrayStorage<7>()
{ return FortranArray<7>(); }
operator GeneralArrayStorage<8>()
{ return FortranArray<8>(); }
operator GeneralArrayStorage<9>()
{ return FortranArray<9>(); }
operator GeneralArrayStorage<10>()
{ return FortranArray<10>(); }
operator GeneralArrayStorage<11>()
{ return FortranArray<11>(); }
};
// A global instance of this class will be placed in
// the blitz library (libblitz.a on unix machines).
_bz_global _bz_fortranTag fortranArray;
/**
Class ColumnMajorArray specializes GeneralArrayStorage to provide
column major arrays (column major ordering, base of 0).
*/
template<int N_rank>
class ColumnMajorArray : public GeneralArrayStorage<N_rank> {
private:
typedef GeneralArrayStorage<N_rank> T_base;
typedef _bz_typename T_base::noInitializeFlag noInitializeFlag;
using T_base::ordering_;
using T_base::ascendingFlag_;
using T_base::base_;
using T_base::paddingPolicy_;
public:
ColumnMajorArray(paddingPolicy pp = defaultPadding)
: GeneralArrayStorage<N_rank>(noInitializeFlag())
{
ordering_ = tensor::i;//Range(0, N_rank - 1);
ascendingFlag_ = true;
base_ = 0;
paddingPolicy_ = pp;
}
};
// This tag class can be used to provide a nicer notation for
// constructing column major arrays: instead of
// Array<int,2> A(3, 3, ColumnMajorArray<2>());
// one can simply write:
// Array<int,2> A(3, 3, columnMajorArray);
// where columnMajorArray is an object of type _bz_columnMajorTag.
class _bz_columnMajorTag {
public:
operator GeneralArrayStorage<1>()
{ return ColumnMajorArray<1>(); }
operator GeneralArrayStorage<2>()
{ return ColumnMajorArray<2>(); }
operator GeneralArrayStorage<3>()
{ return ColumnMajorArray<3>(); }
operator GeneralArrayStorage<4>()
{ return ColumnMajorArray<4>(); }
operator GeneralArrayStorage<5>()
{ return ColumnMajorArray<5>(); }
operator GeneralArrayStorage<6>()
{ return ColumnMajorArray<6>(); }
operator GeneralArrayStorage<7>()
{ return ColumnMajorArray<7>(); }
operator GeneralArrayStorage<8>()
{ return ColumnMajorArray<8>(); }
operator GeneralArrayStorage<9>()
{ return ColumnMajorArray<9>(); }
operator GeneralArrayStorage<10>()
{ return ColumnMajorArray<10>(); }
operator GeneralArrayStorage<11>()
{ return ColumnMajorArray<11>(); }
};
// A global instance of this class will be placed in
// the blitz library (libblitz.a on unix machines).
_bz_global _bz_columnMajorTag columnMajorArray;
BZ_NAMESPACE_END
#ifdef BZ_HAVE_BOOST_MPI
namespace boost { namespace mpi {
template <int N>
struct is_mpi_datatype<blitz::GeneralArrayStorage<N> > : boost::mpl::true_ { };
} }
#endif
#endif // BZ_ARRAY_STORAGE_H
|