diff --git a/include/boost/compute/distributed/command_queue.hpp b/include/boost/compute/distributed/command_queue.hpp index 7ff657912..6225c15ff 100644 --- a/include/boost/compute/distributed/command_queue.hpp +++ b/include/boost/compute/distributed/command_queue.hpp @@ -65,24 +65,40 @@ class command_queue } } - /// Creates a distributed command queue containing command queue for each + /// Creates a distributed command queue containing command queues for each /// corresponding device and context from \p devices and \p contexts. command_queue(const std::vector< ::boost::compute::context> &contexts, - const std::vector &devices, + const std::vector< std::vector > &devices, cl_command_queue_properties properties = 0) { m_context = context(contexts); - size_t n = m_context.size(); - for(size_t i = 0; i < n; i++) { + for(size_t i = 0; i < m_context.size(); i++) { + for(size_t j = 0; j < devices[i].size(); j++) { + m_queues.push_back( + ::boost::compute::command_queue( + m_context.get(i), devices[i][j], properties + ) + ); + } + } + } + + /// Creates a distributed command queue for all devices in \p context. + command_queue(const ::boost::compute::context &context, + cl_command_queue_properties properties = 0) + { + m_context = ::boost::compute::distributed::context(context); + std::vector devices = context.get_devices(); + for(size_t i = 0; i < devices.size(); i++) { m_queues.push_back( ::boost::compute::command_queue( - m_context.get(i), devices[i], properties + context, devices[i], properties ) ); } } - /// Creates a distributed command queue. + /// Creates a distributed command queue containing \p queues. explicit command_queue(const std::vector< ::boost::compute::command_queue> queues) : m_queues(queues) diff --git a/test/test_distributed_command_queue.cpp b/test/test_distributed_command_queue.cpp index 4e3ea6aa1..d17fc3452 100644 --- a/test/test_distributed_command_queue.cpp +++ b/test/test_distributed_command_queue.cpp @@ -52,10 +52,11 @@ BOOST_AUTO_TEST_CASE(construct_from_distributed_context) BOOST_AUTO_TEST_CASE(construct_from_contexts) { std::vector contexts; - std::vector devices; + std::vector > devices; contexts.push_back(context); - devices.push_back(device); + devices.push_back(std::vector()); + devices[0].push_back(device); bc::distributed::command_queue distributed_queue1(contexts, devices); BOOST_CHECK_EQUAL( @@ -63,8 +64,7 @@ BOOST_AUTO_TEST_CASE(construct_from_contexts) 1 ); - contexts.push_back(context); - devices.push_back(device); + devices[0].push_back(device); bc::distributed::command_queue distributed_queue2( contexts, devices, bc::distributed::command_queue::enable_profiling @@ -80,6 +80,21 @@ BOOST_AUTO_TEST_CASE(construct_from_contexts) ); } +BOOST_AUTO_TEST_CASE(construct_from_context) +{ + bc::distributed::command_queue distributed_queue(context); + BOOST_CHECK_EQUAL( + distributed_queue.size(), + context.get_devices().size() + ); + for(size_t i = 0; i < distributed_queue.size(); i++) { + BOOST_CHECK_EQUAL( + distributed_queue.get_context(i), + context + ); + } +} + BOOST_AUTO_TEST_CASE(construct_from_command_queues) { std::vector queues;