Skip to content

Commit c299040

Browse files
authored
Merge pull request #987 from stan-dev/proto/multi-chain
Running multiple chains in one Stan program
2 parents beb8764 + bc4bc94 commit c299040

File tree

12 files changed

+613
-200
lines changed

12 files changed

+613
-200
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,7 @@ make/local
4646
src/docs/**/*.pdf
4747

4848
output.csv
49-
49+
output*.csv
5050
*.d
51+
# gdb
52+
.gdb_history

make/command

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ ifeq ($(CMDSTAN_SUBMODULES),1)
22
bin/cmdstan/stansummary.o : src/cmdstan/stansummary_helper.hpp
33
bin/cmdstan/%.o : src/cmdstan/%.cpp
44
@mkdir -p $(dir $@)
5-
$(COMPILE.cpp) -fvisibility=hidden $(OUTPUT_OPTION) $<
5+
$(COMPILE.cpp) -fvisibility=hidden $(OUTPUT_OPTION) $(LDLIBS) $<
66

77
.PRECIOUS: bin/print$(EXE) bin/stansummary$(EXE) bin/diagnose$(EXE)
88
bin/print$(EXE) bin/stansummary$(EXE) bin/diagnose$(EXE) : CPPFLAGS_MPI =
9-
bin/print$(EXE) bin/stansummary$(EXE) bin/diagnose$(EXE) : LDFLAGS_MPI =
9+
bin/print$(EXE) bin/stansummary$(EXE) bin/diagnose$(EXE) : LDFLAGS_MPI =
1010
bin/print$(EXE) bin/stansummary$(EXE) bin/diagnose$(EXE) : LDLIBS_MPI =
1111
bin/print$(EXE) bin/stansummary$(EXE) bin/diagnose$(EXE) : bin/%$(EXE) : bin/cmdstan/%.o
1212
@mkdir -p $(dir $@)

make/tests

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ test-headers: $(HEADER_TESTS)
5757
TEST_MODELS := $(wildcard src/test/test-models/*.stan)
5858

5959
.PHONY: test-models-hpp
60-
test-models-hpp:
61-
$(MAKE) $(patsubst %.stan,%$(EXE),$(TEST_MODELS))
60+
test-models-hpp:
61+
$(MAKE) $(patsubst %.stan,%$(EXE),$(TEST_MODELS))
6262

6363
##
6464
# Tests that depend on compiled models

makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ build-mpi: $(MPI_TARGETS)
244244

245245
ifeq ($(CMDSTAN_SUBMODULES),1)
246246
.PHONY: build
247-
build: bin/stanc$(EXE) bin/stansummary$(EXE) bin/print$(EXE) bin/diagnose$(EXE) $(LIBSUNDIALS) $(MPI_TARGETS) $(TBB_TARGETS) $(CMDSTAN_MAIN_O) $(PRECOMPILED_MODEL_HEADER)
247+
build: bin/stanc$(EXE) $(LIBSUNDIALS) $(MPI_TARGETS) $(TBB_TARGETS) $(CMDSTAN_MAIN_O) $(PRECOMPILED_MODEL_HEADER) bin/stansummary$(EXE) bin/print$(EXE) bin/diagnose$(EXE)
248248
@echo ''
249249
ifeq ($(OS),Windows_NT)
250250
@echo 'NOTE: Please add $(TBB_BIN_ABSOLUTE_PATH) to your PATH variable.'
@@ -338,3 +338,6 @@ compile_info:
338338
##
339339
.PHONY: print-%
340340
print-% : ; @echo $* = $($*)
341+
342+
.PHONY: clean-build
343+
clean-build: clean-all build

src/cmdstan/arguments/arg_id.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class arg_id : public int_argument {
1111
_name = "id";
1212
_description = "Unique process identifier";
1313
_validity = "id >= 0";
14-
_default = "0";
15-
_default_value = 0;
14+
_default = "1";
15+
_default_value = 1;
1616
_constrained = true;
1717
_good_value = 2.0;
1818
_bad_value = -1.0;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef CMDSTAN_ARGUMENTS_ARG_NUM_CHAINS_HPP
2+
#define CMDSTAN_ARGUMENTS_ARG_NUM_CHAINS_HPP
3+
4+
#include <cmdstan/arguments/singleton_argument.hpp>
5+
6+
namespace cmdstan {
7+
8+
class arg_num_chains : public int_argument {
9+
public:
10+
arg_num_chains() : int_argument() {
11+
_name = "num_chains";
12+
_description = std::string("Number of chains");
13+
_validity = "num_chains > 0";
14+
_default = "1";
15+
_constrained = true;
16+
_good_value = 2.0;
17+
_bad_value = 0.0;
18+
_default = "1";
19+
_default_value = 1;
20+
_value = _default_value;
21+
}
22+
23+
bool is_valid(int value) { return value > 0; }
24+
};
25+
26+
} // namespace cmdstan
27+
#endif
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef CMDSTAN_ARGUMENTS_ARG_NUM_THREADS_HPP
2+
#define CMDSTAN_ARGUMENTS_ARG_NUM_THREADS_HPP
3+
4+
#include <cmdstan/arguments/singleton_argument.hpp>
5+
6+
namespace cmdstan {
7+
8+
class arg_num_threads : public int_argument {
9+
public:
10+
arg_num_threads() : int_argument() {
11+
_name = "num_threads";
12+
_description = std::string("Number of threads available to the program.");
13+
_validity = "num_threads > 0 || num_threads == -1";
14+
_default = "1";
15+
_default_value = 1;
16+
_good_value = 1.0;
17+
_bad_value = -2.0;
18+
_constrained = true;
19+
_value = _default_value;
20+
}
21+
#ifdef STAN_THREADS
22+
bool is_valid(int value) { return value > -2 && value != 0; }
23+
#else
24+
bool is_valid(int value) { return value == 1; }
25+
#endif
26+
};
27+
28+
} // namespace cmdstan
29+
#endif

src/cmdstan/arguments/arg_sample.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define CMDSTAN_ARGUMENTS_ARG_SAMPLE_HPP
33

44
#include <cmdstan/arguments/arg_adapt.hpp>
5+
#include <cmdstan/arguments/arg_num_chains.hpp>
56
#include <cmdstan/arguments/arg_num_samples.hpp>
67
#include <cmdstan/arguments/arg_num_warmup.hpp>
78
#include <cmdstan/arguments/arg_sample_algo.hpp>
@@ -23,6 +24,7 @@ class arg_sample : public categorical_argument {
2324
_subarguments.push_back(new arg_thin());
2425
_subarguments.push_back(new arg_adapt());
2526
_subarguments.push_back(new arg_sample_algo());
27+
_subarguments.push_back(new arg_num_chains());
2628
}
2729
};
2830

0 commit comments

Comments
 (0)