@@ -39,13 +39,13 @@ class Cube : public BaseCube< eT, Cube<eT> >
39
39
typedef eT elem_type; // !< the type of elements stored in the cube
40
40
typedef typename get_pod_type<eT>::result pod_type; // !< if eT is std::complex<T>, pod_type is T; otherwise pod_type is eT
41
41
42
- const uword n_rows; // !< number of rows in each slice (read-only)
43
- const uword n_cols; // !< number of columns in each slice (read-only)
44
- const uword n_elem_slice; // !< number of elements in each slice (read-only)
45
- const uword n_slices; // !< number of slices in the cube (read-only)
46
- const uword n_elem; // !< number of elements in the cube (read-only)
47
- const uword n_alloc; // !< number of allocated elements (read-only); NOTE: n_alloc can be 0, even if n_elem > 0
48
- const uword mem_state;
42
+ const uword n_rows; // !< number of rows in each slice (read-only)
43
+ const uword n_cols; // !< number of columns in each slice (read-only)
44
+ const uword n_elem_slice; // !< number of elements in each slice (read-only)
45
+ const uword n_slices; // !< number of slices in the cube (read-only)
46
+ const uword n_elem; // !< number of elements in the cube (read-only)
47
+ const uword n_alloc; // !< number of allocated elements (read-only); NOTE: n_alloc can be 0, even if n_elem > 0
48
+ const uword mem_state;
49
49
50
50
// mem_state = 0: normal cube which manages its own memory
51
51
// mem_state = 1: use auxiliary memory until a size change
@@ -57,10 +57,27 @@ class Cube : public BaseCube< eT, Cube<eT> >
57
57
58
58
protected:
59
59
60
- arma_aligned const Mat<eT>** const mat_ptrs;
60
+ using mat_type = Mat<eT>;
61
+
62
+ #if defined(ARMA_USE_OPENMP)
63
+ using raw_mat_ptr_type = mat_type*;
64
+ using atomic_mat_ptr_type = mat_type*;
65
+ #elif (!defined(ARMA_DONT_USE_STD_MUTEX))
66
+ using raw_mat_ptr_type = mat_type*;
67
+ using atomic_mat_ptr_type = std::atomic<mat_type*>;
68
+ #else
69
+ using raw_mat_ptr_type = mat_type*;
70
+ using atomic_mat_ptr_type = mat_type*;
71
+ #endif
72
+
73
+ atomic_mat_ptr_type* mat_ptrs = nullptr ;
74
+
75
+ #if (!defined(ARMA_DONT_USE_STD_MUTEX))
76
+ mutable std::mutex mat_mutex; // required for slice()
77
+ #endif
61
78
62
- arma_align_mem Mat<eT>* mat_ptrs_local[ Cube_prealloc::mat_ptrs_size ];
63
- arma_align_mem eT mem_local[ Cube_prealloc::mem_n_elem ]; // local storage, for small cubes
79
+ arma_aligned atomic_mat_ptr_type mat_ptrs_local[ Cube_prealloc::mat_ptrs_size ];
80
+ arma_align_mem eT mem_local[ Cube_prealloc::mem_n_elem ]; // local storage, for small cubes
64
81
65
82
66
83
public:
@@ -124,7 +141,7 @@ class Cube : public BaseCube< eT, Cube<eT> >
124
141
125
142
inline Mat<eT>& slice (const uword in_slice);
126
143
inline const Mat<eT>& slice (const uword in_slice) const ;
127
-
144
+
128
145
arma_inline subview_cube<eT> rows (const uword in_row1, const uword in_row2);
129
146
arma_inline const subview_cube<eT> rows (const uword in_row1, const uword in_row2) const ;
130
147
@@ -445,6 +462,9 @@ class Cube : public BaseCube< eT, Cube<eT> >
445
462
inline void delete_mat ();
446
463
inline void create_mat ();
447
464
465
+ inline void create_mat_ptr (const uword in_slice) const ;
466
+ inline Mat<eT>* get_mat_ptr (const uword in_slice) const ;
467
+
448
468
friend class glue_join ;
449
469
friend class op_reshape ;
450
470
friend class op_resize ;
@@ -471,8 +491,8 @@ class Cube<eT>::fixed : public Cube<eT>
471
491
472
492
static constexpr bool use_extra = (fixed_n_elem > Cube_prealloc::mem_n_elem);
473
493
474
- arma_aligned Mat<eT>* mat_ptrs_local_extra[ (fixed_n_slices > Cube_prealloc::mat_ptrs_size) ? fixed_n_slices : 1 ];
475
- arma_align_mem eT mem_local_extra [ use_extra ? fixed_n_elem : 1 ];
494
+ arma_aligned atomic_mat_ptr_type mat_ptrs_local_extra[ (fixed_n_slices > Cube_prealloc::mat_ptrs_size) ? fixed_n_slices : 1 ];
495
+ arma_align_mem eT mem_local_extra [ use_extra ? fixed_n_elem : 1 ];
476
496
477
497
arma_inline void mem_setup ();
478
498
0 commit comments