// File: /workspace/github_cpp_makefile_star2_O2/melop[P]admixem/Population.cpp
// Function: Population::Init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, char, int, int, double)
void Population::Init(string sPopName,int nPopId,  char nAncestryLabel, int nPopInitSize, int nPopMaxSize, double nMaleRatio) {
	
	this->_nPopId = nPopId;
	this->_sPopName = sPopName;
	this->_nAncestryLabel = nAncestryLabel;
	this->_nPopInitSize = nPopInitSize;
	this->_nMaleRatio = nMaleRatio;
	this->_nPopMaxSize = nPopMaxSize;

	int nMalesToCreate = (int)((double)nPopInitSize * nMaleRatio);
	int nFemalesToCreate = nPopInitSize - nMalesToCreate;

	this->_mpvNewGenMales = new vector< Individual *>[nTotalCPUCore];
	this->_mpvNewGenFemales = new vector< Individual *>[nTotalCPUCore];


	printf("To create... Male: %d  Female %d\n", nMalesToCreate, nFemalesToCreate );
	this->_mpMales.reserve(nMalesToCreate);
	this->_mpFemales.reserve(nFemalesToCreate);
	#pragma omp parallel shared(nMalesToCreate, nFemalesToCreate) 
	//private(pFemale, nCourters, pCourter, vOffSprings, itOffSpring)
	{
	


	#pragma omp for 
	for (int nCPU=0; nCPU<nTotalCPUCore;nCPU++)
	{
		
		//printf("Created Male: %d  Female %d\n", this->_nCurrMales, this->_nCurrFemales );
		while(true) {
			if (nMalesToCreate <= this->_nCurrMales && nFemalesToCreate <= this->_nCurrFemales) {
				break;
			}

			Individual * pNewInd = new Individual(this, nAncestryLabel);

			if (pNewInd->GetSex() == Individual::Male) { // If the created individual is male

				if (nMalesToCreate > this->_nCurrMales) { // if still have room for new males
					#pragma omp critical 
					{
					this->_mpMales.push_back(pNewInd); // put the new male in the population;
					this->_nCurrMales++;
					}
				}
				else {
					delete pNewInd;
					continue;
				}
			}

			if (pNewInd->GetSex() == Individual::Female) { // If the created individual is female

				if (nFemalesToCreate > this->_nCurrFemales) { // if still have room for new females
					#pragma omp critical 
					{
						this->_mpFemales.push_back(pNewInd); // put the new female in the population;
						this->_nCurrFemales++;
					}
				}
				else {
					delete pNewInd;
					continue;
				}
			}
		}//while end.
	} //for end

	} //end parallel
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movsd %xmm0, (%rsp)
movl %r9d, %ebp
movl %r8d, %ebx
movl %ecx, %r15d
movq %rdi, %r14
movl %edx, 0x20(%rdi)
callq 0x7220
movl %r15d, 0x1c(%rsp)
movb %r15b, 0x24(%r14)
movl %ebx, 0x28(%r14)
movsd (%rsp), %xmm1
movsd %xmm1, 0x38(%r14)
movl %ebp, 0x2c(%r14)
leaq 0x1f354(%rip), %rax     # 0x453e4
movl (%rax), %eax
movl %eax, 0x10(%rsp)
movslq %eax, %r12
pushq $0x18
popq %rcx
movq %r12, %rax
mulq %rcx
movq %rax, %r15
movq %rax, 0x20(%rsp)
seto %dl
addq $0x8, %r15
pushq $-0x1
popq %rcx
cmovbq %rcx, %r15
cvtsi2sd %ebx, %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ebp
testb %dl, %dl
cmovneq %rcx, %r15
movq %r15, %rdi
callq 0x7030
movq %rax, %r13
movq %r12, (%rax)
addq $0x8, %r13
movq %r12, (%rsp)
testl %r12d, %r12d
movq 0x20(%rsp), %r12
je 0x2610e
leaq -0x18(%r12), %rcx
movq %rcx, %rax
xorl %edx, %edx
pushq $0x18
popq %rsi
divq %rsi
subq %rdx, %rcx
addq $0x18, %rcx
movq %r13, %rdi
xorl %esi, %esi
movq %rcx, %rdx
callq 0x7230
subl %ebp, %ebx
movq %r13, 0xa8(%r14)
movq %r15, %rdi
callq 0x7030
leaq 0x8(%rax), %r15
movq (%rsp), %rcx
movq %rcx, (%rax)
cmpl $0x0, 0x10(%rsp)
je 0x26154
addq $-0x18, %r12
movq %r12, %rax
xorl %edx, %edx
pushq $0x18
popq %rcx
divq %rcx
subq %rdx, %r12
addq $0x18, %r12
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x7230
movq %r15, 0xb0(%r14)
leaq 0x9740(%rip), %rdi      # 0x2f8a2
movl %ebp, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x7050
leaq 0x48(%r14), %rdi
movslq %ebp, %rsi
movq %rdi, (%rsp)
callq 0x29544
leaq 0x60(%r14), %rdi
movslq %ebx, %rsi
movq %rdi, 0x10(%rsp)
callq 0x29544
xorl %r15d, %r15d
movsbl 0x1c(%rsp), %r12d
leaq 0x1f246(%rip), %rax     # 0x453e4
cmpl (%rax), %r15d
jge 0x26251
cmpl %ebp, 0x30(%r14)
jl 0x261b7
cmpl 0x34(%r14), %ebx
jle 0x26249
movl $0x158, %edi            # imm = 0x158
callq 0x73f0
movq %rax, %r13
movq %rax, %rdi
movq %r14, %rsi
movl %r12d, %edx
callq 0x1fc68
movq %r13, 0x8(%rsp)
movq %r13, %rdi
callq 0x20c92
testl %eax, %eax
jne 0x261fb
cmpl %ebp, 0x30(%r14)
jge 0x26225
movq (%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x2320e
incl 0x30(%r14)
movq 0x8(%rsp), %rdi
callq 0x20c92
cmpl $0x1, %eax
jne 0x261a7
cmpl 0x34(%r14), %ebx
jle 0x26225
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x2320e
incl 0x34(%r14)
jmp 0x261a7
movq 0x8(%rsp), %r13
testq %r13, %r13
je 0x26237
movq %r13, %rdi
callq 0x1fc0e
movl $0x158, %esi            # imm = 0x158
movq %r13, %rdi
callq 0x7400
jmp 0x261a7
incl %r15d
jmp 0x26197
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x158, %esi            # imm = 0x158
movq %r13, %rdi
callq 0x7400
movq %rbx, %rdi
callq 0x76d0