本文整理汇总了C++中MemoryManager::GetMem方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryManager::GetMem方法的具体用法?C++ MemoryManager::GetMem怎么用?C++ MemoryManager::GetMem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemoryManager
的用法示例。
在下文中一共展示了MemoryManager::GetMem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FastMatmulRecursive
void FastMatmulRecursive(LockAndCounter& locker, MemoryManager<Scalar>& mem_mngr, Matrix<Scalar>& A, Matrix<Scalar>& B, Matrix<Scalar>& C, int total_steps, int steps_left, int start_index, double x, int num_threads, Scalar beta) {
// Update multipliers
C.UpdateMultiplier(A.multiplier());
C.UpdateMultiplier(B.multiplier());
A.set_multiplier(Scalar(1.0));
B.set_multiplier(Scalar(1.0));
// Base case for recursion
if (steps_left == 0) {
MatMul(A, B, C);
return;
}
Matrix<Scalar> A11 = A.Subblock(2, 2, 1, 1);
Matrix<Scalar> A12 = A.Subblock(2, 2, 1, 2);
Matrix<Scalar> A21 = A.Subblock(2, 2, 2, 1);
Matrix<Scalar> A22 = A.Subblock(2, 2, 2, 2);
Matrix<Scalar> B11 = B.Subblock(2, 2, 1, 1);
Matrix<Scalar> B12 = B.Subblock(2, 2, 1, 2);
Matrix<Scalar> B21 = B.Subblock(2, 2, 2, 1);
Matrix<Scalar> B22 = B.Subblock(2, 2, 2, 2);
Matrix<Scalar> C11 = C.Subblock(2, 2, 1, 1);
Matrix<Scalar> C12 = C.Subblock(2, 2, 1, 2);
Matrix<Scalar> C21 = C.Subblock(2, 2, 2, 1);
Matrix<Scalar> C22 = C.Subblock(2, 2, 2, 2);
// Matrices to store the results of multiplications.
#ifdef _PARALLEL_
Matrix<Scalar> M1(mem_mngr.GetMem(start_index, 1, total_steps - steps_left, M), C11.m(), C11.m(), C11.n(), C.multiplier());
Matrix<Scalar> M2(mem_mngr.GetMem(start_index, 2, total_steps - steps_left, M), C11.m(), C11.m(), C11.n(), C.multiplier());
Matrix<Scalar> M3(mem_mngr.GetMem(start_index, 3, total_steps - steps_left, M), C11.m(), C11.m(), C11.n(), C.multiplier());
Matrix<Scalar> M4(mem_mngr.GetMem(start_index, 4, total_steps - steps_left, M), C11.m(), C11.m(), C11.n(), C.multiplier());
Matrix<Scalar> M5(mem_mngr.GetMem(start_index, 5, total_steps - steps_left, M), C11.m(), C11.m(), C11.n(), C.multiplier());
Matrix<Scalar> M6(mem_mngr.GetMem(start_index, 6, total_steps - steps_left, M), C11.m(), C11.m(), C11.n(), C.multiplier());
Matrix<Scalar> M7(mem_mngr.GetMem(start_index, 7, total_steps - steps_left, M), C11.m(), C11.m(), C11.n(), C.multiplier());
Matrix<Scalar> M8(mem_mngr.GetMem(start_index, 8, total_steps - steps_left, M), C11.m(), C11.m(), C11.n(), C.multiplier());
#else
Matrix<Scalar> M1(C11.m(), C11.n(), C.multiplier());
Matrix<Scalar> M2(C11.m(), C11.n(), C.multiplier());
Matrix<Scalar> M3(C11.m(), C11.n(), C.multiplier());
Matrix<Scalar> M4(C11.m(), C11.n(), C.multiplier());
Matrix<Scalar> M5(C11.m(), C11.n(), C.multiplier());
Matrix<Scalar> M6(C11.m(), C11.n(), C.multiplier());
Matrix<Scalar> M7(C11.m(), C11.n(), C.multiplier());
Matrix<Scalar> M8(C11.m(), C11.n(), C.multiplier());
#endif
#if defined(_PARALLEL_) && (_PARALLEL_ == _BFS_PAR_ || _PARALLEL_ == _HYBRID_PAR_)
bool sequential1 = should_launch_task(8, total_steps, steps_left, start_index, 1, num_threads);
bool sequential2 = should_launch_task(8, total_steps, steps_left, start_index, 2, num_threads);
bool sequential3 = should_launch_task(8, total_steps, steps_left, start_index, 3, num_threads);
bool sequential4 = should_launch_task(8, total_steps, steps_left, start_index, 4, num_threads);
bool sequential5 = should_launch_task(8, total_steps, steps_left, start_index, 5, num_threads);
bool sequential6 = should_launch_task(8, total_steps, steps_left, start_index, 6, num_threads);
bool sequential7 = should_launch_task(8, total_steps, steps_left, start_index, 7, num_threads);
bool sequential8 = should_launch_task(8, total_steps, steps_left, start_index, 8, num_threads);
#else
bool sequential1 = false;
bool sequential2 = false;
bool sequential3 = false;
bool sequential4 = false;
bool sequential5 = false;
bool sequential6 = false;
bool sequential7 = false;
bool sequential8 = false;
#endif
// M1 = (1 * A11) * (1 * B11)
#if defined(_PARALLEL_) && (_PARALLEL_ == _BFS_PAR_ || _PARALLEL_ == _HYBRID_PAR_)
# pragma omp task if(sequential1) shared(mem_mngr, locker) untied
{
#endif
M1.UpdateMultiplier(Scalar(1));
M1.UpdateMultiplier(Scalar(1));
FastMatmulRecursive(locker, mem_mngr, A11, B11, M1, total_steps, steps_left - 1, (start_index + 1 - 1) * 8, x, num_threads, Scalar(0.0));
#ifndef _PARALLEL_
#endif
#if defined(_PARALLEL_) && (_PARALLEL_ == _BFS_PAR_ || _PARALLEL_ == _HYBRID_PAR_)
locker.Decrement();
}
if (should_task_wait(8, total_steps, steps_left, start_index, 1, num_threads)) {
# pragma omp taskwait
# if defined(_PARALLEL_) && (_PARALLEL_ == _HYBRID_PAR_)
SwitchToDFS(locker, num_threads);
# endif
}
#endif
// M2 = (1 * A12) * (1 * B21)
#if defined(_PARALLEL_) && (_PARALLEL_ == _BFS_PAR_ || _PARALLEL_ == _HYBRID_PAR_)
# pragma omp task if(sequential2) shared(mem_mngr, locker) untied
{
#endif
M2.UpdateMultiplier(Scalar(1));
M2.UpdateMultiplier(Scalar(1));
FastMatmulRecursive(locker, mem_mngr, A12, B21, M2, total_steps, steps_left - 1, (start_index + 2 - 1) * 8, x, num_threads, Scalar(0.0));
#ifndef _PARALLEL_
#endif
#if defined(_PARALLEL_) && (_PARALLEL_ == _BFS_PAR_ || _PARALLEL_ == _HYBRID_PAR_)
//.........这里部分代码省略.........