kspaceFirstOrder3D-OMP  1.2
The C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D
BaseIndexMatrix.cpp
Go to the documentation of this file.
1 /**
2  * @file BaseIndexMatrix.cpp
3  *
4  * @author Jiri Jaros \n
5  * Faculty of Information Technology \n
6  * Brno University of Technology \n
7  * jarosjir@fit.vutbr.cz
8  *
9  * @brief The implementation file containing the base class for index matrices (based on the size_t datatype).
10  *
11  * @version kspaceFirstOrder3D 2.16
12  *
13  * @date 26 July 2011, 14:17 (created) \n
14  * 04 September 2017, 15:03 (revised)
15  *
16  * @copyright Copyright (C) 2017 Jiri Jaros and Bradley Treeby.
17  *
18  * This file is part of the C++ extension of the [k-Wave Toolbox](http://www.k-wave.org).
19  *
20  * This file is part of the k-Wave. k-Wave is free software: you can redistribute it and/or modify it under the terms
21  * of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the
22  * License, or (at your option) any later version.
23  *
24  * k-Wave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
25  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
26  * more details.
27  *
28  * You should have received a copy of the GNU Lesser General Public License along with k-Wave.
29  * If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).
30  */
31 
32 
33 #include <string.h>
34 #include <immintrin.h>
35 #include <assert.h>
36 
38 
39 #include <Utils/DimensionSizes.h>
40 
41 
42 //--------------------------------------------------------------------------------------------------------------------//
43 //---------------------------------------------------- Constants -----------------------------------------------------//
44 //--------------------------------------------------------------------------------------------------------------------//
45 
46 
47 //--------------------------------------------------------------------------------------------------------------------//
48 //------------------------------------------------- Public methods ---------------------------------------------------//
49 //--------------------------------------------------------------------------------------------------------------------//
50 
51 /**
52  * Default constructor
53  */
55  : BaseMatrix(),
56  mSize(0), mCapacity(0),
57  mDimensionSizes(),
58  mRowSize(0), mSlabSize(0),
59  mData(nullptr)
60 {
61 
62 }// end of BaseIndexMatrix
63 //----------------------------------------------------------------------------------------------------------------------
64 
65 /**
66  * Zero all allocated elements.
67  */
69 {
70  #pragma omp parallel for simd schedule(static)
71  for (size_t i = 0; i < mCapacity; i++)
72  {
73  mData[i] = size_t(0);
74  }
75 }// end of zeroMatrix
76 //----------------------------------------------------------------------------------------------------------------------
77 
78 
79 //--------------------------------------------------------------------------------------------------------------------//
80 //------------------------------------------------ Protected methods -------------------------------------------------//
81 //--------------------------------------------------------------------------------------------------------------------//
82 
83 /**
84  * Memory allocation based on the capacity and aligned based on kDataAlignment.
85  */
87 {
88  /* No memory allocated before this function*/
89  assert(mData == nullptr);
90 
91  mData = (size_t*) _mm_malloc(mCapacity * sizeof (size_t), kDataAlignment);
92 
93  if (!mData)
94  {
95  throw std::bad_alloc();
96  }
97 
98  zeroMatrix();
99 }// end of allocateMemory
100 //----------------------------------------------------------------------------------------------------------------------
101 
102 /**
103  * Free memory.
104  */
106 {
107  if (mData) _mm_free(mData);
108 
109  mData = nullptr;
110 }// end of freeMemory
111 //----------------------------------------------------------------------------------------------------------------------
112 
113 //--------------------------------------------------------------------------------------------------------------------//
114 //------------------------------------------------ Private methods ---------------------------------------------------//
115 //--------------------------------------------------------------------------------------------------------------------//
BaseIndexMatrix()
Default constructor.
virtual void zeroMatrix()
Zero all elements of the matrix (NUMA first touch).
size_t * mData
Raw matrix data.
constexpr int kDataAlignment
memory alignment for SSE, SSE2, SSE3, SSE4 (16B)
Abstract base class. The common ancestor defining the common interface and allowing derived classes t...
Definition: BaseMatrix.h:48
virtual void allocateMemory()
Aligned memory allocation (both on CPU and GPU).
The header file containing the structure with 3D dimension sizes.
size_t mCapacity
Total number of allocated elements (in terms of size_t).
The header file containing the base class for index matrices (based on the size_t datatype)...
virtual void freeMemory()
Memory deallocation (both on CPU and GPU)