Repository navigation
Expand file tree
/
Copy pathMemory.cpp
More file actions
109 lines (85 loc) · 1.98 KB
/
Copy pathMemory.cpp
File metadata and controls
109 lines (85 loc) · 1.98 KB
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
/*
DDS, a bridge double dummy solver.
Copyright (C) 2006-2014 by Bo Haglund /
2014-2018 by Bo Haglund & Soren Hein.
See LICENSE and README.
*/
#include "Memory.h"
Memory::Memory()
{
}
Memory::~Memory()
{
Memory::Resize(0, DDS_TT_SMALL, 0, 0);
}
void Memory::ReturnThread(const unsigned thrId)
{
memory[thrId]->transTable->ReturnAllMemory();
memory[thrId]->memUsed = Memory::MemoryInUseMB(thrId);
}
void Memory::Resize(
const unsigned n,
const TTmemory flag,
const int memDefault_MB,
const int memMaximum_MB)
{
if (memory.size() == n)
return;
if (memory.size() > n)
{
// Downsize.
for (unsigned i = n; i < memory.size(); i++)
{
delete memory[i]->transTable;
delete memory[i];
}
memory.resize(static_cast<unsigned>(n));
threadSizes.resize(static_cast<unsigned>(n));
}
else
{
// Upsize.
unsigned oldSize = memory.size();
memory.resize(n);
threadSizes.resize(n);
for (unsigned i = oldSize; i < n; i++)
{
memory[i] = new ThreadData();
if (flag == DDS_TT_SMALL)
{
memory[i]->transTable = new TransTableS;
threadSizes[i] = "S";
}
else
{
memory[i]->transTable = new TransTableL;
threadSizes[i] = "L";
}
memory[i]->transTable->SetMemoryDefault(memDefault_MB);
memory[i]->transTable->SetMemoryMaximum(memMaximum_MB);
memory[i]->transTable->MakeTT();
}
}
}
unsigned Memory::NumThreads() const
{
return static_cast<unsigned>(memory.size());
}
ThreadData * Memory::GetPtr(const unsigned thrId)
{
if (thrId >= memory.size())
{
cout << "Memory::GetPtr: " << thrId << " vs. " << memory.size() << endl;
exit(1);
}
return memory[thrId];
}
double Memory::MemoryInUseMB(const unsigned thrId) const
{
return memory[thrId]->transTable->MemoryInUse() +
8192. * sizeof(relRanksType) / static_cast<double>(1024.);
}
string Memory::ThreadSize(const unsigned thrId) const
{
return threadSizes[thrId];
}