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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
// StxxlWorkThread.cpp : implementation file
//
#include "stdafx.h"
#include "WinGUI.h"
#include "StxxlWorkThread.h"
#include ".\stxxlworkthread.h"
#include "WorkDialog.h"
#include "WinGUIDlg.h"
#include "UserTypes.h"
// CStxxlWorkThread
IMPLEMENT_DYNCREATE(CStxxlWorkThread, CWinThread)
CStxxlWorkThread::CStxxlWorkThread()
{ }
CStxxlWorkThread::~CStxxlWorkThread()
{ }
BOOL CStxxlWorkThread::InitInstance()
{
// TODO: perform and per-thread initialization here
return TRUE;
}
int CStxxlWorkThread::ExitInstance()
{
// TODO: perform any per-thread cleanup here
return CWinThread::ExitInstance();
}
BEGIN_MESSAGE_MAP(CStxxlWorkThread, CWinThread)
END_MESSAGE_MAP()
// CStxxlWorkThread message handlers
template <class T>
void CStxxlWorkThread::FillRandom(CString & path, LONGLONG filesize, T dummy)
{
stxxl::wincall_file myfile(LPCSTR(dlg->m_Filename), stxxl::file::CREAT |
stxxl::file::DIRECT | stxxl::file::RDWR);
stxxl::int64 vectorsize = dlg->m_Filesize * 4096 / sizeof(T);
stxxl::vector<T> myvector(&myfile);
myvector.resize(vectorsize);
stxxl::generate(myvector.begin(), myvector.end(), my_rnd(), 4);
}
template <class T>
void CStxxlWorkThread::FillValue(CString & path, LONGLONG filesize, int value, T dummy)
{
stxxl::wincall_file myfile(LPCSTR(dlg->m_Filename), stxxl::file::CREAT |
stxxl::file::DIRECT | stxxl::file::RDWR);
stxxl::int64 vectorsize = dlg->m_Filesize * 4096 / sizeof(T);
stxxl::vector<T> myvector(&myfile);
myvector.resize(vectorsize);
std::fill(myvector.begin(), myvector.end(), value);
}
template <class Cmp, class T>
void CStxxlWorkThread::Sort(CString & path, unsigned mem_usage, Cmp cmp, T dummy)
{
stxxl::wincall_file myfile(LPCSTR(dlg->m_Filename), stxxl::file::CREAT |
stxxl::file::DIRECT | stxxl::file::RDWR);
stxxl::vector<T> myvector(&myfile);
if ((myvector.size() * sizeof(T)) % 4096)
{
AfxMessageBox("File can not be sorted because it is accessed with direct I/O\n"
"and its size is not a multiple of 4KBytes.");
return;
}
stxxl::sort(myvector.begin(), myvector.end(), cmp, mem_usage * 1024 * 1024);
}
template <class Cmp, class T>
void CStxxlWorkThread::CheckOrder(CString & path, Cmp cmp, T dummy)
{
stxxl::wincall_file myfile(LPCSTR(dlg->m_Filename), stxxl::file::CREAT |
stxxl::file::DIRECT | stxxl::file::RDWR);
stxxl::vector<T> myvector(&myfile);
if ((myvector.size() * sizeof(T)) % 4096)
{
AfxMessageBox("File can not be sorted because it is accessed with direct I/O\n"
"and its size is not a multiple of 4KBytes.");
return;
}
bool sorted = stxxl::is_sorted(myvector.begin(), myvector.end(), cmp);
if (sorted)
AfxMessageBox("The file is sorted");
else
AfxMessageBox("The file is NOT sorted");
}
template <class T>
void CStxxlWorkThread::DelDuplicates(CString & path, unsigned mem_usage, T dummy)
{
stxxl::wincall_file myfile(LPCSTR(dlg->m_Filename), stxxl::file::CREAT |
stxxl::file::DIRECT | stxxl::file::RDWR);
stxxl::vector<T> myvector(&myfile);
if ((myvector.size() * sizeof(T)) % 4096)
{
AfxMessageBox("File can not be sorted because it is accessed with direct I/O\n"
"and its size is not a multiple of 4KBytes.");
return;
}
stxxl::sort(myvector.begin(), myvector.end(), LessCmp<T>(), mem_usage * 1024 * 1024);
std::unique(myvector.begin(), myvector.end());
}
int CStxxlWorkThread::Run()
{
// TODO: Add your specialized code here and/or call the base class
switch (taskid)
{
case FILL_RANDOM:
if (dlg->m_Format1)
FillRandom(dlg->m_Filename, dlg->m_Filesize, type2());
else
FillRandom(dlg->m_Filename, dlg->m_Filesize, type1());
break;
case FILL_VALUE:
if (dlg->m_Format1)
FillValue(dlg->m_Filename, dlg->m_Filesize, dlg->m_Key, type2());
else
FillValue(dlg->m_Filename, dlg->m_Filesize, dlg->m_Key, type1());
break;
case SORT_ASC:
if (dlg->m_Format1)
Sort(dlg->m_Filename, dlg->m_MemUsage, LessCmp<type2>(), type2());
else
Sort(dlg->m_Filename, dlg->m_MemUsage, LessCmp<type1>(), type1());
break;
case SORT_DESC:
if (dlg->m_Format1)
Sort(dlg->m_Filename, dlg->m_MemUsage, GreaterCmp<type2>(), type2());
else
Sort(dlg->m_Filename, dlg->m_MemUsage, GreaterCmp<type1>(), type1());
break;
case CHECK_ASC:
if (dlg->m_Format1)
CheckOrder(dlg->m_Filename, LessCmp<type2>(), type2());
else
CheckOrder(dlg->m_Filename, LessCmp<type1>(), type1());
break;
case CHECK_DESC:
if (dlg->m_Format1)
CheckOrder(dlg->m_Filename, GreaterCmp<type2>(), type2());
else
CheckOrder(dlg->m_Filename, GreaterCmp<type1>(), type1());
break;
case DEL_DUP:
if (dlg->m_Format1)
DelDuplicates(dlg->m_Filename, dlg->m_MemUsage, type2());
else
DelDuplicates(dlg->m_Filename, dlg->m_MemUsage, type1());
break;
default:
AfxMessageBox("Command not known or not implemented");
};
PostMessage(notifywindow->m_hWnd, WM_WORK_THREAD_FINISHED, 0, 0);
m_bAutoDelete = TRUE;
return CWinThread::Run();
}
CStxxlWorkThread::CStxxlWorkThread(int taskid_, CWinGUIDlg * dlg_, CWnd * notifywindow_) :
taskid(taskid_), dlg(dlg_), notifywindow(notifywindow_)
{ }
|