// File: /workspace/github_cpp_makefile_star2_O1/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, 0x10(%rsp)
movl %r9d, %ebp
movl %r8d, %ebx
movl %ecx, %r15d
movq %rdi, %r14
movl %edx, 0x20(%rdi)
callq 0x71d0
movl %r15d, 0x24(%rsp)
movb %r15b, 0x24(%r14)
movl %ebx, 0x28(%r14)
movsd 0x10(%rsp), %xmm1
movsd %xmm1, 0x38(%r14)
movl %ebp, 0x2c(%r14)
leaq 0x1f432(%rip), %rax     # 0x493bc
movl (%rax), %eax
movl %eax, 0x18(%rsp)
movslq %eax, %r12
movl $0x18, %ecx
movq %r12, %rax
mulq %rcx
movq %rax, %r13
seto %al
addq $0x8, %r13
movq $-0x1, %rcx
cmovbq %rcx, %r13
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ebp
testb %al, %al
cmovneq %rcx, %r13
movq %r13, %rdi
callq 0x7030
movq %rax, %r15
movq %r12, (%rax)
addq $0x8, %r15
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
testl %r12d, %r12d
je 0x2a012
leaq (%r12,%r12,2), %rax
leaq -0x18(,%rax,8), %rax
mulq %rcx
shrq $0x4, %rdx
leaq (%rdx,%rdx,2), %rax
leaq 0x18(,%rax,8), %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x71e0
subl %ebp, %ebx
movq %r15, 0xa8(%r14)
movq %r13, %rdi
callq 0x7030
leaq 0x8(%rax), %r15
movq %r12, (%rax)
cmpl $0x0, 0x18(%rsp)
je 0x2a064
leaq (%r12,%r12,2), %rax
leaq -0x18(,%rax,8), %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rcx
shrq $0x4, %rdx
leaq (%rdx,%rdx,2), %rax
leaq 0x18(,%rax,8), %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x71e0
movq %r15, 0xb0(%r14)
leaq 0xd858(%rip), %rdi      # 0x378ca
xorl %r12d, %r12d
movl %ebp, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x7060
leaq 0x48(%r14), %rdi
movslq %ebp, %rsi
movq %rdi, 0x10(%rsp)
callq 0x2e7cc
leaq 0x60(%r14), %rdi
movslq %ebx, %rsi
movq %rdi, 0x18(%rsp)
callq 0x2e7cc
leaq 0x1f313(%rip), %rax     # 0x493bc
cmpl $0x0, (%rax)
jle 0x2a1a7
movsbl 0x24(%rsp), %r13d
cmpl %ebp, 0x30(%r14)
jl 0x2a0c8
cmpl 0x34(%r14), %ebx
jle 0x2a194
movl $0x158, %edi            # imm = 0x158
callq 0x7380
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
movl %r13d, %edx
callq 0x21e64
movq %r15, 0x8(%rsp)
movq %r15, %rdi
callq 0x2361c
testl %eax, %eax
jne 0x2a126
cmpl %ebp, 0x30(%r14)
jge 0x2a154
movq 0x50(%r14), %rsi
cmpq 0x58(%r14), %rsi
je 0x2a113
movq 0x8(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x50(%r14)
jmp 0x2a122
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x275b2
incl 0x30(%r14)
movq 0x8(%rsp), %rdi
callq 0x2361c
cmpl $0x1, %eax
jne 0x2a0b8
cmpl 0x34(%r14), %ebx
jle 0x2a154
movq 0x68(%r14), %rsi
cmpq 0x70(%r14), %rsi
je 0x2a17c
movq 0x8(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x68(%r14)
jmp 0x2a18b
movq 0x8(%rsp), %r15
testq %r15, %r15
je 0x2a0b8
movq %r15, %rdi
callq 0x21dfc
movl $0x158, %esi            # imm = 0x158
movq %r15, %rdi
callq 0x7390
jmp 0x2a0b8
movq 0x18(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x275b2
incl 0x34(%r14)
jmp 0x2a0b8
incl %r12d
leaq 0x1f21e(%rip), %rax     # 0x493bc
cmpl (%rax), %r12d
jl 0x2a0b8
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 %r15, %rdi
callq 0x7390
movq %rbx, %rdi
callq 0x76a0