// File: /workspace/github_cpp_makefile_star2_O2/j-faria[P]kima/examples/trends/../../DNest4/code/SamplerImpl.h
// Function: DNest4::Sampler<RVmodel>::run(unsigned int)
void Sampler<ModelType>::run(unsigned int thin)
{
	// Set the thining of terminal output
	thin_print = thin;

#ifndef NO_THREADS
	// Set up threads and barrier
	// Delete if necessary (shouldn't be needed!)
	if(barrier != nullptr)
		delete barrier;
	for(auto& thread: threads)
	{
		if(thread != nullptr)
			delete thread;
	}

	// Create the barrier
	barrier = new Barrier(num_threads);

	// Create and launch threads
	for(size_t i=0; i<threads.size(); ++i)
	{
		// Function to run on each thread
		auto func = std::bind(&Sampler<ModelType>::run_thread, this, i);

		// Allocate and create the thread
		threads[i] = new std::thread(func);
	}

	// Join and de-allocate all threads and barrier
	for(auto& t: threads)
		t->join();

	// Delete dynamically allocated stuff and point to nullptr
	delete barrier;
	barrier = nullptr;
	for(auto& t: threads)
	{
		delete t;
		t = nullptr;
	}
#else
	for(size_t i=0; i<threads.size(); ++i) run_thread(i);
#endif

	// Save the sampler state to a file.
	std::fstream fout("sampler_state.txt", std::ios::out);
	print(fout);
	fout.close();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movq %rdi, %rbx
movl %esi, 0x4(%rdi)
movq 0x20(%rdi), %r14
testq %r14, %r14
je 0x21136
leaq 0x28(%r14), %rdi
callq 0x6730
pushq $0x68
popq %rsi
movq %r14, %rdi
callq 0x6450
movq 0x8(%rbx), %r12
movq 0x10(%rbx), %r13
pushq $0x8
popq %r14
cmpq %r13, %r12
je 0x21169
movq (%r12), %r15
testq %r15, %r15
je 0x21163
movq %r15, %rdi
callq 0x35524
movq %r15, %rdi
movq %r14, %rsi
callq 0x6450
addq $0x8, %r12
jmp 0x21142
pushq $0x68
popq %rdi
callq 0x6440
movq %rax, %r14
movl 0x28(%rbx), %esi
movq %rax, %rdi
callq 0x37a08
movq %r14, 0x20(%rbx)
xorl %r13d, %r13d
pushq $0x8
popq %r14
leaq 0x8(%rsp), %r15
movq 0x8(%rbx), %r12
movq 0x10(%rbx), %rbp
movq %rbp, %rax
subq %r12, %rax
sarq $0x3, %rax
cmpq %rax, %r13
jae 0x211f2
leaq 0x14385(%rip), %rax     # 0x35532
movq %rax, 0x8(%rsp)
andq $0x0, 0x10(%rsp)
movq %r13, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
movq %r14, %rdi
callq 0x6440
movq %rax, %r12
movq %rax, %rdi
movq %r15, %rsi
callq 0x3574e
movq 0x8(%rbx), %rax
movq %r12, (%rax,%r13,8)
incq %r13
jmp 0x2118f
movq (%r12), %rdi
callq 0x6680
addq $0x8, %r12
cmpq %rbp, %r12
jne 0x211e5
movq 0x20(%rbx), %r14
testq %r14, %r14
je 0x21209
leaq 0x28(%r14), %rdi
callq 0x6730
pushq $0x68
popq %rsi
movq %r14, %rdi
callq 0x6450
andq $0x0, 0x20(%rbx)
movq 0x8(%rbx), %r12
movq 0x10(%rbx), %r13
pushq $0x8
popq %r14
cmpq %r13, %r12
je 0x21251
movq (%r12), %r15
testq %r15, %r15
je 0x2123b
movq %r15, %rdi
callq 0x35524
movq %r15, %rdi
movq %r14, %rsi
callq 0x6450
andq $0x0, (%r12)
addq $0x8, %r12
jmp 0x21225
leaq 0x2a704(%rip), %rsi     # 0x4b95c
leaq 0x8(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x6530
leaq 0x18(%rsp), %rsi
movq %rbx, %rdi
callq 0x357be
leaq 0x8(%rsp), %rdi
callq 0x6050
leaq 0x8(%rsp), %rdi
callq 0x60c0
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
pushq $0x68
popq %rsi
movq %r14, %rdi
jmp 0x212bb
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x60c0
jmp 0x212c0
movq %rax, %rbx
pushq $0x8
popq %rsi
movq %r12, %rdi
callq 0x6450
movq %rbx, %rdi
callq 0x66e0