// File: /workspace/github_cpp_makefile_star2_O3/richardposner[P]BioNetFit2/src/code/Swarm.cpp
// Function: Swarm::initPSOswarm(bool)
void Swarm::initPSOswarm(bool resumeFit) {
	vector<unsigned int> finishedParticles;
	//unsigned int numFinishedParticles = 0;

	if (options.verbosity >= 3) {
		cout << "Launching swarm" << endl;
	}

	// Launch all particles
	//for (unsigned int p = 1; p <= options.swarmSize; ++p) {
	//	launchParticle(p);
	//}

	//if (options.verbosity >= 3) {
	//	cout << "Waiting for particles to finish" << endl;
	//}

	// Wait until they are all finished so we can initialize
	// stuff for subsequent iterations
	/*while(numFinishedParticles < options.swarmSize) {
		// Check for our finished particles

		cout << "RAQUEL swarm size is " << options.swarmSize << " finished: " << numFinishedParticles << endl;
		finishedParticles = checkMasterMessages();
		numFinishedParticles += finishedParticles.size();

		// Sleep for a second
		usleep(1000000);
	}

	*/
	//Raquel replaced the loop above by a synchronous generation
	runGeneration();



	// Fill a vector with all pID's to send for processing
	vector<unsigned int> allParticles;
	for (int p = 1; p <= options.swarmSize; ++p) {
		allParticles.push_back(p);
	}

	// Send all pID's in for processing (update velocities and positions)
	processParticlesPSO(allParticles, false);

	// Set our optimum
	optimum_ = particleBestFitsByFit_.begin()->first;

	// If we're using enhanced stop criteria, update the enhanced stop variables
	if (options.enhancedStop) {
		// Initialize our particle weights and weighted average position
		updateEnhancedStop();
	}


}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
cmpl $0x3, 0x1614(%rdi)
jb 0x9c0a2
movq 0xd9f41(%rip), %r14     # 0x175fa8
leaq 0x645cf(%rip), %rsi     # 0x10063d
movl $0xf, %edx
movq %r14, %rdi
callq 0x22ab0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq %r14, %rdi
callq 0x22050
movq %rax, %rdi
callq 0x22660
movq %rbx, %rdi
callq 0x8cd7e
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
cmpl $0x0, 0x1620(%rbx)
jle 0x9c102
xorl %ebp, %ebp
leaq 0x10(%rsp), %r14
leaq 0xc(%rsp), %r15
incl %ebp
movl %ebp, 0xc(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x9c0ef
movl %ebp, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x9c0fa
movq %r14, %rdi
movq %r15, %rdx
callq 0xaeef8
cmpl 0x1620(%rbx), %ebp
jl 0x9c0d0
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xa8002
leaq 0x30(%rsp), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x886d0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x9c137
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
movq 0x1ac8(%rbx), %rax
movsd 0x20(%rax), %xmm0
movsd %xmm0, 0x1d90(%rbx)
cmpb $0x1, 0x16f8(%rbx)
jne 0x9c15c
movq %rbx, %rdi
callq 0x8738c
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x9c173
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x9c19f
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
jmp 0x9c19f
jmp 0x9c19c
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x9c1b6
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
movq %rbx, %rdi
callq 0x23240