// File: /workspace/github_cpp_makefile_star2_O3/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 0x2082c
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 0x2085b
movq (%r14), %rdi
testq %rdi, %rdi
je 0x20855
cmpq $0x0, (%rdi)
jne 0x2099a
movl $0x8, %esi
callq 0x6460
addq $0x8, %r14
jmp 0x20834
movl $0x68, %edi
callq 0x6450
movq %rax, %r14
movl 0x28(%rbx), %esi
movq %rax, %rdi
callq 0x382bc
movq %r14, 0x20(%rbx)
movq 0x8(%rbx), %r15
movq 0x10(%rbx), %rbp
cmpq %r15, %rbp
je 0x208f3
xorl %r12d, %r12d
leaq 0x14e62(%rip), %r13     # 0x356f0
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 0x35966
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 0x20893
jmp 0x208f3
movq (%r15), %rdi
callq 0x66b0
addq $0x8, %r15
cmpq %rbp, %r15
jne 0x208e7
movq 0x20(%rbx), %r14
testq %r14, %r14
je 0x2090a
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 0x20951
movq (%r14), %rdi
testq %rdi, %rdi
je 0x2093a
cmpq $0x0, (%rdi)
jne 0x2099a
movl $0x8, %esi
callq 0x6460
movq $0x0, (%r14)
addq $0x8, %r14
jmp 0x20927
leaq 0x24147(%rip), %rsi     # 0x44a9f
leaq 0x8(%rsp), %rdi
movl $0x10, %edx
callq 0x6550
leaq 0x18(%rsp), %rsi
movq %rbx, %rdi
callq 0x359dc
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 0x209c6
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x60c0
jmp 0x209cb
movq %rax, %rbx
movl $0x8, %esi
movq %r15, %rdi
callq 0x6460
movq %rbx, %rdi
callq 0x6710
nop