[go: up one dir, main page]

Menu

[e7d36e]: / tools / create_files.cpp  Maximize  Restore  History

Download this file

270 lines (219 with data), 7.7 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
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/***************************************************************************
* tools/create_files.cpp
*
* Part of the STXXL. See http://stxxl.sourceforge.net
*
* Copyright (C) 2003 Roman Dementiev <dementiev@mpi-sb.mpg.de>
* Copyright (C) 2007 Andreas Beckmann <beckmann@mpi-inf.mpg.de>
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
**************************************************************************/
#include <cstdio>
#include <iomanip>
#include <vector>
#include <stxxl/io>
#include <stxxl/aligned_alloc>
#include <stxxl/bits/common/cmdline.h>
#if !STXXL_WINDOWS
#include <unistd.h>
#endif
using stxxl::request_ptr;
using stxxl::file;
using stxxl::timestamp;
using stxxl::unsigned_type;
#ifdef BLOCK_ALIGN
#undef BLOCK_ALIGN
#endif
#define BLOCK_ALIGN 4096
#define NOREAD
//#define DO_ONLY_READ
#define POLL_DELAY 1000
#define RAW_ACCESS
//#define WATCH_TIMES
#define CHECK_AFTER_READ 0
#ifdef WATCH_TIMES
void watch_times(request_ptr reqs[], unsigned n, double* out)
{
bool* finished = new bool[n];
unsigned count = 0;
unsigned i = 0;
for (i = 0; i < n; i++)
finished[i] = false;
while (count != n)
{
usleep(POLL_DELAY);
i = 0;
for (i = 0; i < n; i++)
{
if (!finished[i])
if (reqs[i]->poll())
{
finished[i] = true;
out[i] = timestamp();
count++;
}
}
}
delete[] finished;
}
void out_stat(double start, double end, double* times, unsigned n, const std::vector<std::string>& names)
{
for (unsigned i = 0; i < n; i++)
{
std::cout << i << " " << names[i] << " took " <<
100. * (times[i] - start) / (end - start) << " %" << std::endl;
}
}
#endif
#define MB (1024 * 1024)
int create_files(int argc, char* argv[])
{
std::vector<std::string> disks_arr;
stxxl::uint64 offset = 0, length;
stxxl::cmdline_parser cp;
cp.add_param_bytes("filesize", "Number of bytes to write to files.", length);
cp.add_param_stringlist("filename", "Paths to files to write.", disks_arr);
if (!cp.process(argc, argv))
return -1;
stxxl::uint64 endpos = offset + length;
for (size_t i = 0; i < disks_arr.size(); ++i)
{
unlink(disks_arr[i].c_str());
std::cout << "# Add disk: " << disks_arr[i] << std::endl;
}
const size_t ndisks = disks_arr.size();
#if STXXL_WINDOWS
unsigned_type buffer_size = 64 * MB;
#else
unsigned_type buffer_size = 256 * MB;
#endif
const unsigned_type buffer_size_int = buffer_size / sizeof(int);
unsigned chunks = 2;
const unsigned_type chunk_size = buffer_size / chunks;
const unsigned_type chunk_size_int = chunk_size / sizeof(int);
unsigned i = 0, j = 0;
int* buffer = (int*)stxxl::aligned_alloc<BLOCK_ALIGN>(buffer_size * ndisks);
file** disks = new file*[ndisks];
request_ptr* reqs = new request_ptr[ndisks * chunks];
#ifdef WATCH_TIMES
double* r_finish_times = new double[ndisks];
double* w_finish_times = new double[ndisks];
#endif
for (i = 0; i < ndisks * buffer_size_int; i++)
buffer[i] = i;
for (i = 0; i < ndisks; i++)
{
#if STXXL_WINDOWS
#ifdef RAW_ACCESS
disks[i] = new stxxl::wincall_file(disks_arr[i],
file::CREAT | file::RDWR | file::DIRECT, i);
#else
disks[i] = new stxxl::wincall_file(disks_arr[i],
file::CREAT | file::RDWR, i);
#endif
#else
#ifdef RAW_ACCESS
disks[i] = new stxxl::syscall_file(disks_arr[i],
file::CREAT | file::RDWR | file::DIRECT, i);
#else
disks[i] = new stxxl::syscall_file(disks_arr[i],
file::CREAT | file::RDWR, i);
#endif
#endif
}
while (offset < endpos)
{
const unsigned_type current_block_size =
length
? (unsigned_type)std::min<stxxl::int64>(buffer_size, endpos - offset)
: buffer_size;
const unsigned_type current_chunk_size = current_block_size / chunks;
std::cout << "Disk offset " << std::setw(7) << offset / MB << " MiB: " << std::fixed;
double begin = timestamp(), end;
#ifndef DO_ONLY_READ
for (i = 0; i < ndisks; i++)
{
for (j = 0; j < chunks; j++)
reqs[i * chunks + j] =
disks[i]->awrite(buffer + buffer_size_int * i + j * chunk_size_int,
offset + j * current_chunk_size,
current_chunk_size);
}
#ifdef WATCH_TIMES
watch_times(reqs, ndisks, w_finish_times);
#else
wait_all(reqs, ndisks * chunks);
#endif
end = timestamp();
#if 0
std::cout << "WRITE\nDisks: " << ndisks
<< " \nElapsed time: " << end - begin
<< " \nThroughput: " << int(double(buffer_size * ndisks) / MB / (end - begin))
<< " MiB/s \nPer one disk:"
<< int((buffer_size) / MB / (end - begin)) << " MiB/s"
<< std::endl;
#endif
#ifdef WATCH_TIMES
out_stat(begin, end, w_finish_times, ndisks, disks_arr);
#endif
std::cout << std::setw(7) << int(double(current_block_size) / MB / (end - begin)) << " MiB/s,";
#endif
#ifndef NOREAD
begin = timestamp();
for (i = 0; i < ndisks; i++)
{
for (j = 0; j < chunks; j++)
reqs[i * chunks + j] = disks[i]->aread(buffer + buffer_size_int * i + j * chunk_size_int,
offset + j * current_chunk_size,
current_chunk_size);
}
#ifdef WATCH_TIMES
watch_times(reqs, ndisks, r_finish_times);
#else
wait_all(reqs, ndisks * chunks);
#endif
end = timestamp();
#if 0
std::cout << "READ\nDisks: " << ndisks
<< " \nElapsed time: " << end - begin
<< " \nThroughput: " << int(double(buffer_size * ndisks) / MB / (end - begin))
<< " MiB/s \nPer one disk:"
<< int(double(buffer_size) / MB / (end - begin)) << " MiB/s"
<< std::endl;
#endif
std::cout << int(double(current_block_size) / MB / (end - begin)) << " MiB/s" << std::endl;
#ifdef WATCH_TIMES
out_stat(begin, end, r_finish_times, ndisks, disks_arr);
#endif
if (CHECK_AFTER_READ) {
for (int i = 0; unsigned(i) < ndisks * buffer_size_int; i++)
{
if (buffer[i] != i)
{
int ibuf = i / buffer_size_int;
int pos = i % buffer_size_int;
std::cout << "Error on disk " << ibuf << " position " << std::hex << std::setw(8) << offset + pos * sizeof(int)
<< " got: " << std::hex << std::setw(8) << buffer[i] << " wanted: " << std::hex << std::setw(8) << i
<< std::dec << std::endl;
i = (ibuf + 1) * buffer_size_int; // jump to next
}
}
}
#else
std::cout << std::endl;
#endif
offset += current_block_size;
}
#ifdef WATCH_TIMES
delete[] r_finish_times;
delete[] w_finish_times;
#endif
delete[] reqs;
for (i = 0; i < ndisks; i++)
delete disks[i];
delete[] disks;
stxxl::aligned_dealloc<BLOCK_ALIGN>(buffer);
return 0;
}