| kspaceFirstOrder3D-OMP 1.1 The C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D

- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Friends Pages
BaseIndexMatrix.cpp
Go to the documentation of this file.
1 /**
2 * @file BaseIndexMatrix.cpp
3 * @author Jiri Jaros \n
4 * Faculty of Information Technology\n
5 * Brno University of Technology \n
6 * jarosjir@fit.vutbr.cz
7 *
8 * @brief The implementation file containing the base class for index
9 * matrices (based on the size_t datatype).
10 *
11 * @version kspaceFirstOrder3D 2.15
12 *
13 * @date 26 July 2011, 14:17 (created) \n
14 * 24 September 2014, 14:58 (revised)
15 *
16 * @section License
17 * This file is part of the C++ extension of the k-Wave Toolbox (http://www.k-wave.org). .\n
18 * Copyright (C) 2014 Jiri Jaros and Bradley Treeby
19 *
20 * This file is part of k-Wave. k-Wave is free software: you can redistribute it
21 * and/or modify it under the terms of the GNU Lesser General Public License as
22 * published by the Free Software Foundation, either version 3 of the License,
23 * or (at your option) any later version.
24 *
25 * k-Wave is distributed in the hope that it will be useful, but
26 * WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28 * See the GNU Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public License
31 * along with k-Wave. If not, see <http://www.gnu.org/licenses/>.
32 */
33
34
35 #include <string.h>
36 #include <immintrin.h>
37 #include <assert.h>
38
39 #include <MatrixClasses/BaseIndexMatrix.h>
40
41 #include <Utils/DimensionSizes.h>
42 #include <Utils/ErrorMessages.h>
43
44
45 //----------------------------------------------------------------------------//
46 // Constants //
47 //----------------------------------------------------------------------------//
48
49
50 //----------------------------------------------------------------------------//
51 // Definitions //
52 //----------------------------------------------------------------------------//
53
54
55
56 //----------------------------------------------------------------------------//
57 // Implementation //
58 // public methods //
59 //----------------------------------------------------------------------------//
60
61 /**
62 * Zero all allocated elements.
63 *
64 */
65 void TBaseIndexMatrix::ZeroMatrix()
66 {
67 ///@todo: This breaks the first touch policy! - however we don't know the distribution
68 memset(pMatrixData, 0, pTotalAllocatedElementCount * sizeof(size_t));
69 }// end of ZeroMatrix
70 //------------------------------------------------------------------------------
71
72
73
74 //----------------------------------------------------------------------------//
75 // Implementation //
76 // protected methods //
77 //----------------------------------------------------------------------------//
78
79
80 /**
81 * Memory allocation based on the total number of elements. \n
82 * Memory is aligned by the DATA_ALIGNMENT and all elements are zeroed.
83 */
84 void TBaseIndexMatrix::AllocateMemory()
85 {
86 /* No memory allocated before this function*/
87 assert(pMatrixData == NULL);
88
89 pMatrixData = (size_t *) _mm_malloc(pTotalAllocatedElementCount * sizeof (size_t), DATA_ALIGNMENT);
90
91 if (!pMatrixData)
92 {
93 fprintf(stderr,Matrix_ERR_FMT_NotEnoughMemory, "TBaseIndexMatrix");
94 throw bad_alloc();
95 }
96
97 ZeroMatrix();
98 }// end of AllocateMemory
99 //------------------------------------------------------------------------------
100
101 /**
102 * Free memory.
103 */
104 void TBaseIndexMatrix::FreeMemory()
105 {
106 if (pMatrixData) _mm_free(pMatrixData);
107 pMatrixData = NULL;
108 }// end of MemoryDealocation
109 //------------------------------------------------------------------------------
110
111
112
113
114 //----------------------------------------------------------------------------//
115 // Implementation //
116 // private methods //
117 //----------------------------------------------------------------------------//
TBaseIndexMatrix::AllocateMemory
virtual void AllocateMemory()
Memory allocation.
Definition: BaseIndexMatrix.cpp:84
TBaseIndexMatrix::pTotalAllocatedElementCount
size_t pTotalAllocatedElementCount
Total number of allocated elements (the array size).
Definition: BaseIndexMatrix.h:105
ErrorMessages.h
The header file containing all error messages of the project.
TBaseIndexMatrix::ZeroMatrix
virtual void ZeroMatrix()
Zero all elements of the matrix (NUMA first touch).
Definition: BaseIndexMatrix.cpp:65
DimensionSizes.h
The header file containing the structure with 3D dimension sizes.
TBaseIndexMatrix::pMatrixData
size_t * pMatrixData
Raw matrix data.
Definition: BaseIndexMatrix.h:116
BaseIndexMatrix.h
The header file containing the base class for index matrices (based on the size_t datatype)...
DATA_ALIGNMENT
const int DATA_ALIGNMENT
memory alignment for SSE, SSE2, SSE3, SSE4 (16B)
Definition: DimensionSizes.h:53
Matrix_ERR_FMT_NotEnoughMemory
const char *const Matrix_ERR_FMT_NotEnoughMemory
Matrix class error message.
Definition: ErrorMessages.h:81
TBaseIndexMatrix::FreeMemory
virtual void FreeMemory()
Memory deallocation.
Definition: BaseIndexMatrix.cpp:104