Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: map_rect_concurrent with parallel STL backends #1085

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adjust num_threads_test
  • Loading branch information
wds15 committed Dec 16, 2018
commit 42b344155f7f4d9a23d84cdb54cfeb3e8e77bc04
2 changes: 1 addition & 1 deletion stan/math/parallel/get_num_threads.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace stan {
namespace math {
namespace internal {
/**
* Get number of threads to to use. The function uses the environment
* Get number of threads to use. The function uses the environment
* variable STAN_NUM_THREADS and follows these conventions:
*
* - STAN_NUM_THREADS is not defined => num_threads=1
Expand Down
21 changes: 9 additions & 12 deletions test/unit/math/prim/mat/functor/num_threads_test.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#ifndef STAN_THREADS
#define STAN_THREADS
#endif

#include <stan/math/prim/mat/functor/map_rect_concurrent.hpp>
#include <stan/math/parallel/get_num_threads.hpp>
#include <gtest/gtest.h>
#include <test/unit/util.hpp>

Expand All @@ -17,29 +13,30 @@ void set_n_threads_var(const char* value) {

TEST(num_threads, correct_values) {
set_n_threads_var("10");
EXPECT_EQ(stan::math::internal::get_num_threads(100), 10);
EXPECT_EQ(stan::math::internal::get_num_threads(), 10);

set_n_threads_var("4");
EXPECT_EQ(stan::math::internal::get_num_threads(3), 3);
EXPECT_EQ(stan::math::internal::get_num_threads(), 4);

set_n_threads_var("-1");
EXPECT_GE(stan::math::internal::get_num_threads(5), 1);
EXPECT_GE(stan::math::internal::get_num_threads(),
std::thread::hardware_concurrency());
}

TEST(num_threads, incorrect_values) {
set_n_threads_var("abc");
EXPECT_THROW_MSG(stan::math::internal::get_num_threads(5),
EXPECT_THROW_MSG(stan::math::internal::get_num_threads(),
std::invalid_argument, "positive number or -1");

set_n_threads_var("1c");
EXPECT_THROW_MSG(stan::math::internal::get_num_threads(5),
EXPECT_THROW_MSG(stan::math::internal::get_num_threads(),
std::invalid_argument, "positive number or -1");

set_n_threads_var("-2");
EXPECT_THROW_MSG(stan::math::internal::get_num_threads(5),
EXPECT_THROW_MSG(stan::math::internal::get_num_threads(),
std::invalid_argument, "must be positive or -1");

set_n_threads_var("0");
EXPECT_THROW_MSG(stan::math::internal::get_num_threads(5),
EXPECT_THROW_MSG(stan::math::internal::get_num_threads(),
std::invalid_argument, "must be positive or -1");
}