// File: richardposner[P]BioNetFit2/src/code/Particle.cpp
// Function: Particle::finalizeSim(unsigned int)
void Particle::finalizeSim(unsigned int mid) {
	unsigned int subParID = calcsubParID(mid);
	if ((mid<0)|| (mid >= swarm_->getNumModels()) || (!getSubParticle(mid)) || (!models.at(mid)) || (dataFiles_.at(mid).empty())){
		outputError("finalizeSim Failed. Invalid SubParticle.  PID:"+ toString(id_) + "  model id:" + toString(mid)+ "  subParID:" + toString(subParID)+". Quitting !!!");
	}
	if (swarm_->options.verbosity >= 3) {cout << "Finalizing simulation. Started" << endl;}

	// Calculate our fit
	calculateFit(false, mid);  //razi: was calculateFit(), check if local should be false


	// Put our simulation params into the message vector
	if ((!this->getSubParticle(mid)) || (fitCalcs.at(mid).empty())){
		cout<<"can  not finalize simulation for subParticle with model id:"<<mid<<endl;
		return;
	}

		// Put our fit calc into the message vector
	swarm_->swarmComm->univMessageSender.push_back(toString(fitCalcs.at(mid).at(currentGeneration_)));
		//cout << "stored fit calc of " << fitCalcs.at(currentGeneration_) << " as " << swarm_->swarmComm->univMessageSender[0] << endl;


	//razi: here the slave fills in the values for free parameters [the list and order may be different for each model, should be taken care of by Master]
	for (map<string,double>::iterator i = simParams_.at(mid).begin(); i != simParams_.at(mid).end(); ++i){
		//cout << "stored param of " << i->second << endl;
		swarm_->swarmComm->univMessageSender.push_back(toString(i->second));
	}

	// Tell the swarm master that we're finished
	if (swarm_->options.verbosity >= 3) {
		cout << "Telling master that my simulation is finished" << endl;
	}

	swarm_->swarmComm->sendToSwarm(subParID, 0, SIMULATION_END, false, swarm_->swarmComm->univMessageSender);
	// Reset the message vector
	swarm_->swarmComm->univMessageSender.clear();
	if (swarm_->options.verbosity >= 3) {cout << "Finalizing simulation. Completed" << endl;}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1e0, %rsp            # imm = 0x1E0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
movl -0xc(%rbp), %esi
callq 0xac1e0
movl %eax, -0x10(%rbp)
cmpl $0x0, -0xc(%rbp)
jb 0xac2e3
movq -0x1a0(%rbp), %rax
movl -0xc(%rbp), %ecx
movl %ecx, -0x1a4(%rbp)
movq 0xa8(%rax), %rdi
callq 0x8dec0
movl %eax, %ecx
movl -0x1a4(%rbp), %eax
cmpl %ecx, %eax
jae 0xac2e3
movq -0x1a0(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0xb2a40
cmpq $0x0, %rax
je 0xac2e3
movq -0x1a0(%rbp), %rdi
addq $0x78, %rdi
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0x45190
cmpq $0x0, (%rax)
je 0xac2e3
movq -0x1a0(%rbp), %rdi
addq $0x90, %rdi
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0xb3430
movq %rax, %rdi
callq 0xb3a10
testb $0x1, %al
jne 0xac2e3
jmp 0xac554
movq -0x1a0(%rbp), %rax
movl 0x40(%rax), %esi
leaq -0xf0(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
callq 0x17e460
movq -0x1b0(%rbp), %rdx
leaq 0x12fcc0(%rip), %rsi    # 0x1dbfce
leaq -0xd0(%rbp), %rdi
callq 0x8e0f0
jmp 0xac31c
leaq 0x12f20f(%rip), %rdx    # 0x1db532
leaq -0xb0(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x441f0
jmp 0xac338
movl -0xc(%rbp), %esi
leaq -0x120(%rbp), %rdi
callq 0x17e460
jmp 0xac349
leaq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
leaq -0x120(%rbp), %rdx
callq 0x9c7d0
jmp 0xac365
leaq 0x12ec18(%rip), %rdx    # 0x1daf84
leaq -0x70(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x441f0
jmp 0xac37e
movl -0x10(%rbp), %esi
leaq -0x140(%rbp), %rdi
callq 0x17e460
jmp 0xac38f
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x140(%rbp), %rdx
callq 0x9c7d0
jmp 0xac3a5
leaq 0x12f2a1(%rip), %rdx    # 0x1db64d
leaq -0x30(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x441f0
jmp 0xac3bb
leaq -0x30(%rbp), %rdi
callq 0x17e420
jmp 0xac3c6
leaq -0x30(%rbp), %rdi
callq 0x311e8
leaq -0x50(%rbp), %rdi
callq 0x311e8
leaq -0x140(%rbp), %rdi
callq 0x311e8
leaq -0x70(%rbp), %rdi
callq 0x311e8
leaq -0x90(%rbp), %rdi
callq 0x311e8
leaq -0x120(%rbp), %rdi
callq 0x311e8
leaq -0xb0(%rbp), %rdi
callq 0x311e8
leaq -0xd0(%rbp), %rdi
callq 0x311e8
leaq -0xf0(%rbp), %rdi
callq 0x311e8
jmp 0xac554
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0xac543
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0xac537
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0xac52b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0xac51f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0xac513
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0xac50a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0xac4fe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0xac4f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x311e8
leaq -0x50(%rbp), %rdi
callq 0x311e8
leaq -0x140(%rbp), %rdi
callq 0x311e8
leaq -0x70(%rbp), %rdi
callq 0x311e8
leaq -0x90(%rbp), %rdi
callq 0x311e8
leaq -0x120(%rbp), %rdi
callq 0x311e8
leaq -0xb0(%rbp), %rdi
callq 0x311e8
leaq -0xd0(%rbp), %rdi
callq 0x311e8
leaq -0xf0(%rbp), %rdi
callq 0x311e8
jmp 0xac85e
movq -0x1a0(%rbp), %rax
movq 0xa8(%rax), %rax
cmpl $0x3, 0x1614(%rax)
jb 0xac58d
movq 0x2289de(%rip), %rdi    # 0x2d4f50
leaq 0x12fa84(%rip), %rsi    # 0x1dbffd
callq 0x2ff50
movq %rax, %rdi
movq 0x228a40(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
movq -0x1a0(%rbp), %rdi
movl -0xc(%rbp), %edx
xorl %esi, %esi
callq 0xa9130
movq -0x1a0(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0xb2a40
cmpq $0x0, %rax
je 0xac5d6
movq -0x1a0(%rbp), %rdi
addq $0x18, %rdi
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0xb2f10
movq %rax, %rdi
callq 0xb4290
testb $0x1, %al
jne 0xac5d6
jmp 0xac608
movq 0x228973(%rip), %rdi    # 0x2d4f50
leaq 0x12fa38(%rip), %rsi    # 0x1dc01c
callq 0x2ff50
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x30640
movq %rax, %rdi
movq 0x2289ca(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xac855
movq -0x1a0(%rbp), %rdi
movq 0xa8(%rdi), %rax
movq (%rax), %rax
movq %rax, -0x1c0(%rbp)
addq $0x18, %rdi
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0xb2f10
movq %rax, %rdi
movq -0x1a0(%rbp), %rax
movl 0xb0(%rax), %eax
movl %eax, -0x164(%rbp)
leaq -0x164(%rbp), %rsi
callq 0xb42b0
movsd (%rax), %xmm0
leaq -0x160(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x17e490
movq -0x1c0(%rbp), %rdi
movq -0x1b8(%rbp), %rsi
callq 0xb39c0
jmp 0xac67c
leaq -0x160(%rbp), %rdi
callq 0x311e8
movq -0x1a0(%rbp), %rdi
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0xb2a00
movq %rax, %rdi
callq 0x9c670
movq %rax, -0x170(%rbp)
movq -0x1a0(%rbp), %rdi
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0xb2a00
movq %rax, %rdi
callq 0x966d0
movq %rax, -0x178(%rbp)
leaq -0x170(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x9c6a0
testb $0x1, %al
jne 0xac6e4
jmp 0xac798
movq -0x1a0(%rbp), %rax
movq 0xa8(%rax), %rax
movq (%rax), %rax
movq %rax, -0x1d0(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x9c7b0
movsd 0x20(%rax), %xmm0
leaq -0x198(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x17e490
movq -0x1d0(%rbp), %rdi
movq -0x1c8(%rbp), %rsi
callq 0xb39c0
jmp 0xac735
leaq -0x198(%rbp), %rdi
callq 0x311e8
leaq -0x170(%rbp), %rdi
callq 0x97360
jmp 0xac6a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x311e8
jmp 0xac85e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x311e8
jmp 0xac85e
movq -0x1a0(%rbp), %rax
movq 0xa8(%rax), %rax
cmpl $0x3, 0x1614(%rax)
jb 0xac7d1
movq 0x22879a(%rip), %rdi    # 0x2d4f50
leaq 0x12f89b(%rip), %rsi    # 0x1dc058
callq 0x2ff50
movq %rax, %rdi
movq 0x2287fc(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
movq -0x1a0(%rbp), %rax
movq 0xa8(%rax), %rcx
movq (%rcx), %rdi
movl -0x10(%rbp), %esi
movq 0xa8(%rax), %rax
movq (%rax), %r9
xorl %r8d, %r8d
movl $0xd, %ecx
movl %r8d, %edx
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
callq 0xcd520
movq -0x1a0(%rbp), %rax
movq 0xa8(%rax), %rax
movq (%rax), %rdi
callq 0x451d0
movq -0x1a0(%rbp), %rax
movq 0xa8(%rax), %rax
cmpl $0x3, 0x1614(%rax)
jb 0xac855
movq 0x228716(%rip), %rdi    # 0x2d4f50
leaq 0x12f845(%rip), %rsi    # 0x1dc086
callq 0x2ff50
movq %rax, %rdi
movq 0x228778(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq
movq -0xf8(%rbp), %rdi
callq 0x30170
nopw (%rax,%rax)