本文整理汇总了C++中utils::get_time_difference方法的典型用法代码示例。如果您正苦于以下问题:C++ utils::get_time_difference方法的具体用法?C++ utils::get_time_difference怎么用?C++ utils::get_time_difference使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils
的用法示例。
在下文中一共展示了utils::get_time_difference方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: gather
void Gatherer::gather()
{
zmq::message_t start_msg;
zmq::message_t start_msg2;
input_socket.recv(&start_msg);
size_t* input_buffer = static_cast<size_t*>(start_msg.data());
size_t num_jobs = *input_buffer;
input_socket.recv(&start_msg2);
input_buffer = static_cast<size_t*>(start_msg2.data());
size_t n = *input_buffer;
struct timeval tstart, tend;
gettimeofday (&tstart, NULL);
//std::cout << "Received problem info: " << num_jobs << " " << n << std::endl;
Real* parallel_assembly_times = new Real[num_jobs];
Real total_assembly_time(0);
Merger* merger = new Merger(n, num_jobs);
for(size_t i(0); i < num_jobs; ++i)
{
zmq::message_t msg;
input_socket.recv(&msg);
Byte* input_buffer = static_cast<Byte*>(msg.data());
JobResult job_result;
job_result.unpack(input_buffer);
merger->merge_job_result(job_result);
parallel_assembly_times[i] = job_result.get_assembly_time();
}
zmq::message_t kill_msg(5);
memcpy(kill_msg.data(), "KILL", 5);
control_socket.send(kill_msg);
//std::cout << "Published kill signal!" << std::endl;
const Real* matrix_ptr = merger->get_matrix_ptr();
const Real* rhs_ptr = merger->get_rhs_ptr();
gettimeofday (&tend, NULL);
total_assembly_time = get_time_difference(tstart, tend);
const Real* x_ptr(NULL);
Solution* solution(NULL);
if(solve)
{
Solver solver(matrix_ptr, rhs_ptr, n);
delete merger;
Solution* solution = solver.get_solution_alloc();
x_ptr = solution->get_x_ptr();
}
else
{
Real* solution = new Real[n];
for(size_t i(0); i < n; ++i)
{
solution[i] = 0.0;
}
x_ptr = solution;
}
size_t total_assembly_time_size = sizeof(total_assembly_time);
size_t parallel_assembly_time_size = total_assembly_time_size*num_jobs;
size_t solution_size = n*sizeof(Real);
zmq::message_t parallel_assembly_time_msg(parallel_assembly_time_size);
zmq::message_t total_assembly_time_msg(total_assembly_time_size);
zmq::message_t solution_msg(solution_size);
memcpy(parallel_assembly_time_msg.data(), parallel_assembly_times, parallel_assembly_time_size);
memcpy(total_assembly_time_msg.data(), &total_assembly_time, total_assembly_time_size);
memcpy(solution_msg.data(), x_ptr, solution_size);
delete[] parallel_assembly_times;
control_socket.send(parallel_assembly_time_msg, ZMQ_SNDMORE);
control_socket.send(total_assembly_time_msg, ZMQ_SNDMORE);
control_socket.send(solution_msg);
//std::cout << "Published solution!" << std::endl;
if(solve)
{
delete solution;
}
else
{
delete[] x_ptr;
}
}