Increase column limit in format
This commit is contained in:
parent
f90d9f6e24
commit
fabc2daba9
@ -8,5 +8,6 @@ AllowShortLambdasOnASingleLine: Inline
|
|||||||
AllowShortLoopsOnASingleLine: 'false'
|
AllowShortLoopsOnASingleLine: 'false'
|
||||||
AlwaysBreakBeforeMultilineStrings: 'true'
|
AlwaysBreakBeforeMultilineStrings: 'true'
|
||||||
IndentWidth: '4'
|
IndentWidth: '4'
|
||||||
|
ColumnLimit: 100
|
||||||
|
|
||||||
...
|
...
|
||||||
|
54
main.cpp
54
main.cpp
@ -49,11 +49,9 @@ struct World {
|
|||||||
|
|
||||||
inline void set(int x, int y, bool val) { data[y][x] = val; }
|
inline void set(int x, int y, bool val) { data[y][x] = val; }
|
||||||
|
|
||||||
inline int get_num_neighbors(int left, int right, int up, int down, int x,
|
inline int get_num_neighbors(int left, int right, int up, int down, int x, int y) {
|
||||||
int y) {
|
return get_value(left, down) + get_value(x, down) + get_value(right, down) +
|
||||||
return get_value(left, down) + get_value(x, down) +
|
get_value(left, y) + get_value(right, y) + get_value(left, up) + get_value(x, up) +
|
||||||
get_value(right, down) + get_value(left, y) +
|
|
||||||
get_value(right, y) + get_value(left, up) + get_value(x, up) +
|
|
||||||
get_value(right, up);
|
get_value(right, up);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,8 +74,7 @@ void generation_omp(World &world, int *neighbor_counts) {
|
|||||||
for (int y = 0; y < size_y; y++) {
|
for (int y = 0; y < size_y; y++) {
|
||||||
// Wrap y
|
// Wrap y
|
||||||
// This happens rarely enough that this if isn't a huge problem, and it
|
// This happens rarely enough that this if isn't a huge problem, and it
|
||||||
// would be tedious
|
// would be tedious to handle both this and x manually.
|
||||||
// to handle both this and x manually.
|
|
||||||
int up = y - 1;
|
int up = y - 1;
|
||||||
int down = y + 1;
|
int down = y + 1;
|
||||||
|
|
||||||
@ -87,13 +84,11 @@ void generation_omp(World &world, int *neighbor_counts) {
|
|||||||
down -= size_y;
|
down -= size_y;
|
||||||
|
|
||||||
// Handle x == 0
|
// Handle x == 0
|
||||||
neighbor_counts[y * size_x + 0] =
|
neighbor_counts[y * size_x + 0] = world.get_num_neighbors(loop_x, 1, up, down, 0, y);
|
||||||
world.get_num_neighbors(loop_x, 1, up, down, 0, y);
|
|
||||||
|
|
||||||
// Handle 'normal' x
|
// Handle 'normal' x
|
||||||
for (int x = 1; x < loop_x; x++) {
|
for (int x = 1; x < loop_x; x++) {
|
||||||
neighbor_counts[y * size_x + x] =
|
neighbor_counts[y * size_x + x] = world.get_num_neighbors(x - 1, x + 1, up, down, x, y);
|
||||||
world.get_num_neighbors(x - 1, x + 1, up, down, x, y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle x == loop_x (== size_x - 1, we're just re-using the variable
|
// Handle x == loop_x (== size_x - 1, we're just re-using the variable
|
||||||
@ -127,8 +122,7 @@ void generation_seq(World &world, int *neighbor_counts) {
|
|||||||
for (int y = 0; y < size_y; y++) {
|
for (int y = 0; y < size_y; y++) {
|
||||||
// Wrap y
|
// Wrap y
|
||||||
// This happens rarely enough that this if isn't a huge problem, and it
|
// This happens rarely enough that this if isn't a huge problem, and it
|
||||||
// would be tedious
|
// would be tedious to handle both this and x manually.
|
||||||
// to handle both this and x manually.
|
|
||||||
int up = y - 1;
|
int up = y - 1;
|
||||||
int down = y + 1;
|
int down = y + 1;
|
||||||
|
|
||||||
@ -138,13 +132,11 @@ void generation_seq(World &world, int *neighbor_counts) {
|
|||||||
down -= size_y;
|
down -= size_y;
|
||||||
|
|
||||||
// Handle x == 0
|
// Handle x == 0
|
||||||
neighbor_counts[y * size_x + 0] =
|
neighbor_counts[y * size_x + 0] = world.get_num_neighbors(loop_x, 1, up, down, 0, y);
|
||||||
world.get_num_neighbors(loop_x, 1, up, down, 0, y);
|
|
||||||
|
|
||||||
// Handle 'normal' x
|
// Handle 'normal' x
|
||||||
for (int x = 1; x < loop_x; x++) {
|
for (int x = 1; x < loop_x; x++) {
|
||||||
neighbor_counts[y * size_x + x] =
|
neighbor_counts[y * size_x + x] = world.get_num_neighbors(x - 1, x + 1, up, down, x, y);
|
||||||
world.get_num_neighbors(x - 1, x + 1, up, down, x, y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle x == loop_x (== size_x - 1, we're just re-using the variable
|
// Handle x == loop_x (== size_x - 1, we're just re-using the variable
|
||||||
@ -170,8 +162,8 @@ void print_usage() {
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void main_opencl(std::string infile, std::string outfile, int num_generations,
|
void main_opencl(std::string infile, std::string outfile, int num_generations, bool measure,
|
||||||
bool measure, bool use_gpu) {
|
bool use_gpu) {
|
||||||
Timing *timing = Timing::getInstance();
|
Timing *timing = Timing::getInstance();
|
||||||
|
|
||||||
// Get Nvidia CUDA platform
|
// Get Nvidia CUDA platform
|
||||||
@ -215,8 +207,7 @@ void main_opencl(std::string infile, std::string outfile, int num_generations,
|
|||||||
cl::Program program(context, sources);
|
cl::Program program(context, sources);
|
||||||
if (program.build({default_device}) != CL_SUCCESS) {
|
if (program.build({default_device}) != CL_SUCCESS) {
|
||||||
std::cout << "Error building: "
|
std::cout << "Error building: "
|
||||||
<< program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(default_device)
|
<< program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(default_device) << std::endl;
|
||||||
<< std::endl;
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,8 +258,7 @@ void main_opencl(std::string infile, std::string outfile, int num_generations,
|
|||||||
cl::CommandQueue queue(context, default_device);
|
cl::CommandQueue queue(context, default_device);
|
||||||
|
|
||||||
// Push write commands to queue
|
// Push write commands to queue
|
||||||
queue.enqueueWriteBuffer(buffer_previous, CL_TRUE, 0, sizeof(bool) * n,
|
queue.enqueueWriteBuffer(buffer_previous, CL_TRUE, 0, sizeof(bool) * n, world);
|
||||||
world);
|
|
||||||
queue.enqueueWriteBuffer(buffer_new, CL_TRUE, 0, sizeof(bool) * n, result);
|
queue.enqueueWriteBuffer(buffer_new, CL_TRUE, 0, sizeof(bool) * n, result);
|
||||||
queue.enqueueWriteBuffer(buffer_size, CL_TRUE, 0, sizeof(int) * 2, size);
|
queue.enqueueWriteBuffer(buffer_size, CL_TRUE, 0, sizeof(int) * 2, size);
|
||||||
|
|
||||||
@ -287,14 +277,12 @@ void main_opencl(std::string infile, std::string outfile, int num_generations,
|
|||||||
gol_kernel.setArg(2, buffer_size);
|
gol_kernel.setArg(2, buffer_size);
|
||||||
|
|
||||||
// Run it
|
// Run it
|
||||||
queue.enqueueNDRangeKernel(gol_kernel, cl::NullRange, cl::NDRange(n),
|
queue.enqueueNDRangeKernel(gol_kernel, cl::NullRange, cl::NDRange(n), cl::NullRange);
|
||||||
cl::NullRange);
|
|
||||||
queue.finish();
|
queue.finish();
|
||||||
|
|
||||||
// Swap the previous buffer with the new buffer, as we will want to use
|
// Swap the previous buffer with the new buffer, as we will want to use
|
||||||
// our result from this loop
|
// our result from this loop as the input of the next loop (overwriting the previous result,
|
||||||
// as the input of the next loop (overwriting the previous result,
|
// which is not needed anymore)
|
||||||
// which is not needed anymore)
|
|
||||||
std::swap(buffer_previous, buffer_new);
|
std::swap(buffer_previous, buffer_new);
|
||||||
}
|
}
|
||||||
queue.finish();
|
queue.finish();
|
||||||
@ -306,11 +294,9 @@ void main_opencl(std::string infile, std::string outfile, int num_generations,
|
|||||||
// depending on
|
// depending on
|
||||||
// whether we're in swapped mode or not at the moment
|
// whether we're in swapped mode or not at the moment
|
||||||
if (num_generations % 2 == 0) {
|
if (num_generations % 2 == 0) {
|
||||||
queue.enqueueReadBuffer(buffer_previous, CL_TRUE, 0, sizeof(bool) * n,
|
queue.enqueueReadBuffer(buffer_previous, CL_TRUE, 0, sizeof(bool) * n, result);
|
||||||
result);
|
|
||||||
} else {
|
} else {
|
||||||
queue.enqueueReadBuffer(buffer_new, CL_TRUE, 0, sizeof(bool) * n,
|
queue.enqueueReadBuffer(buffer_new, CL_TRUE, 0, sizeof(bool) * n, result);
|
||||||
result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the result
|
// Write the result
|
||||||
@ -338,8 +324,8 @@ void main_opencl(std::string infile, std::string outfile, int num_generations,
|
|||||||
timing->stopFinalization();
|
timing->stopFinalization();
|
||||||
}
|
}
|
||||||
|
|
||||||
void main_classic(std::string infile, std::string outfile, int num_generations,
|
void main_classic(std::string infile, std::string outfile, int num_generations, bool measure,
|
||||||
bool measure, Mode mode) {
|
Mode mode) {
|
||||||
Timing *timing = Timing::getInstance();
|
Timing *timing = Timing::getInstance();
|
||||||
|
|
||||||
// Read in the start state
|
// Read in the start state
|
||||||
|
Loading…
x
Reference in New Issue
Block a user