Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F62945022
poisson.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, May 16, 16:55
Size
2 KB
Mime Type
text/x-c
Expires
Sat, May 18, 16:55 (2 d)
Engine
blob
Format
Raw Data
Handle
17710871
Attached To
R11201 phpc-2021
poisson.cc
View Options
/* -------------------------------------------------------------------------- */
#include "simulation.hh"
/* -------------------------------------------------------------------------- */
#include <chrono>
#include <iostream>
#include <sstream>
#include <tuple>
#include <chrono>
/* -------------------------------------------------------------------------- */
#include <cuda_runtime.h>
/* -------------------------------------------------------------------------- */
#define EPSILON 0.005
typedef std::chrono::high_resolution_clock clk;
typedef std::chrono::duration<double> second;
static void usage(const std::string & prog_name) {
std::cerr << prog_name << " <grid_size> <block_size [default: 32]>" << std::endl;
exit(0);
}
int main(int argc, char * argv[]) {
if (argc < 2) usage(argv[0]);
int N;
try {
N = std::stoi(argv[1]);
} catch(std::invalid_argument &) {
usage(argv[0]);
}
int block_size = 32;
if (argc == 3) {
try {
block_size = std::stoi(argv[2]);
} catch(std::invalid_argument &) {
usage(argv[0]);
}
}
// By default, we use device 0,
int dev_id = 0;
cudaDeviceProp device_prop;
cudaGetDevice(&dev_id);
cudaGetDeviceProperties(&device_prop, dev_id);
if (device_prop.computeMode == cudaComputeModeProhibited) {
std::cerr << "Error: device is running in <Compute Mode Prohibited>, no "
"threads can use ::cudaSetDevice()"
<< std::endl;
return -1;
}
auto error = cudaGetLastError();
if(error != cudaSuccess) {
throw std::runtime_error("Error Launching Kernel: "
+ std::string(cudaGetErrorName(error)) + " - "
+ std::string(cudaGetErrorString(error)));
} else {
std::cout << "GPU Device " << dev_id << ": \"" << device_prop.name
<< "\" with compute capability " << device_prop.major << "."
<< device_prop.minor << std::endl;
}
Simulation simu(N, N);
simu.set_initial_conditions();
auto start = clk::now();
int k = simu.compute(block_size);
auto end = clk::now();
second time = end - start;
std::cout << block_size << " " << N << " "
<< k << " " << std::scientific << " "
<< time.count() << std::endl;
return 0;
}
Event Timeline
Log In to Comment