// File: /workspace/github_cpp_makefile_star2_O1/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 0x21122
leaq 0x28(%r14), %rdi
callq 0x6760
movl $0x68, %esi
movq %r14, %rdi
callq 0x6460
movq 0x8(%rbx), %r14
movq 0x10(%rbx), %r15
cmpq %r15, %r14
je 0x21151
movq (%r14), %rdi
testq %rdi, %rdi
je 0x2114b
cmpq $0x0, (%rdi)
jne 0x21290
movl $0x8, %esi
callq 0x6460
addq $0x8, %r14
jmp 0x2112a
movl $0x68, %edi
callq 0x6450
movq %rax, %r14
movl 0x28(%rbx), %esi
movq %rax, %rdi
callq 0x3a85c
movq %r14, 0x20(%rbx)
movq 0x8(%rbx), %r15
movq 0x10(%rbx), %rbp
cmpq %r15, %rbp
je 0x211e9
xorl %r12d, %r12d
leaq 0x16b04(%rip), %r13     # 0x37c88
leaq 0x8(%rsp), %r14
movq %r13, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq %r12, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
movl $0x8, %edi
callq 0x6450
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
callq 0x37ec4
movq 0x8(%rbx), %rax
movq %r15, (%rax,%r12,8)
incq %r12
movq 0x8(%rbx), %r15
movq 0x10(%rbx), %rbp
movq %rbp, %rax
subq %r15, %rax
sarq $0x3, %rax
cmpq %rax, %r12
jb 0x21189
jmp 0x211e9
movq (%r15), %rdi
callq 0x66b0
addq $0x8, %r15
cmpq %rbp, %r15
jne 0x211dd
movq 0x20(%rbx), %r14
testq %r14, %r14
je 0x2120d
leaq 0x28(%r14), %rdi
callq 0x6760
movl $0x68, %esi
movq %r14, %rdi
callq 0x6460
movq $0x0, 0x20(%rbx)
movq 0x8(%rbx), %r14
movq 0x10(%rbx), %r15
cmpq %r15, %r14
je 0x21247
movq (%r14), %rdi
testq %rdi, %rdi
je 0x2123a
cmpq $0x0, (%rdi)
jne 0x21290
movl $0x8, %esi
callq 0x6460
movq $0x0, (%r14)
addq $0x8, %r14
jmp 0x2121d
leaq 0x26381(%rip), %rsi     # 0x475cf
leaq 0x8(%rsp), %rdi
movl $0x10, %edx
callq 0x6550
leaq 0x18(%rsp), %rsi
movq %rbx, %rdi
callq 0x37f4a
leaq 0x8(%rsp), %rdi
callq 0x6060
leaq 0x8(%rsp), %rdi
callq 0x60c0
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x60f0
movq %rax, %rbx
movl $0x68, %esi
movq %r14, %rdi
jmp 0x212bc
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x60c0
jmp 0x212c1
movq %rax, %rbx
movl $0x8, %esi
movq %r15, %rdi
callq 0x6460
movq %rbx, %rdi
callq 0x6710
nop