// File: /workspace/github_cpp_makefile_star2_O3/richardposner[P]BioNetFit2/src/code/Pheromones.cpp
// Function: Pheromones::init(Swarm*)
void Pheromones::init(Swarm *s) {
	swarm_ = s;
	unsigned int nSubPar= swarm_->options.swarmSize * swarm_->options.models.size()+1; //razi:number of subparticles, +1 since starts from 1

	// Using MPI
	if (swarm_->options.useCluster && (swarm_->options.clusterSoftware == "mpi" || swarm_->options.clusterSoftware == "slurm") ) {
		// Set up our MPI environment and communicator

		//std::cout<<"Pheromones Initialization: MPI\n";
		//env_ = new mpi::environment();
	    // Initialize the MPI environment
	    MPI_Init(NULL, NULL);
	    // Get the number of processes
	    int world_size;
	    MPI_Comm_size(MPI_COMM_WORLD, &world_size);
	    if (swarm_->options.verbosity>=3) {

	    	cout << "Defined mpi environment" << endl;
	    }
//		world_ = new mpi::communicator();
		 // Get the rank of the process
		    int world_rank;
		    MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);

		    //cout << "My rank is " << world_rank << " and I have just started." << endl;
		    if (swarm_->options.verbosity>=3) {

		    	cout << "Defined world communicator" << endl;
		    }
		//  boost::mpi::environment env;
		 // boost::mpi::communicator world_;
		//scout << "Hello World! from process " << world_.rank() << endl;
	}
	else if (swarm_->options.clusterSoftware == "BNF2mpi"){
	    if (swarm_->options.verbosity>=3) {

			cout << "Detected BNF2mpi in Pheromones init()" << endl;
	    }
			//env_ = new mpi::environment();
		    MPI_Init(NULL, NULL);
			    // Get the number of processes
			    int world_size;
			    MPI_Comm_size(MPI_COMM_WORLD, &world_size);
			    if (swarm_->options.verbosity>=3) {

			    	cout << "Defined mpi environment" << endl;
			    }
		//		world_ = new mpi::communicator();
				 // Get the rank of the process
				    int world_rank;
				    MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);

				    if (swarm_->options.verbosity>=3) {

				    	cout << "My rank is " << world_rank << "and I have just started." << endl;

				    	cout << "Defined world communicator" << endl;
				    }
				//  boost::mpi::environment env;
	}
	// Using IPC
	else {

		//std::cout << "init ipc" << std::endl;
		if (s->isMaster) {
			std::cout<<"Pheromones Initialization: IPC: Master\n";
			for (unsigned int i = 0; i <= nSubPar ; ++i) {
				//std::cout << "creating: " << std::toString(static_cast<long long int>(i)) << std::endl;
				message_queue *smq;

				try {
					smq = new message_queue(create_only, toString(i).c_str(), MAX_SWARM_NUM_MESSAGE, MAX_SWARM_MESSAGE_SIZE);
				} catch (boost::interprocess::interprocess_exception e) {
					message_queue::remove(toString(i).c_str());
					smq = new message_queue(create_only, toString(i).c_str(), MAX_SWARM_NUM_MESSAGE, MAX_SWARM_MESSAGE_SIZE);
				}
				smq_.push_back(smq);
			}
		}
		else {
			std::cout<<"Pheromones Initialization: IPC: Slave\n";
			for (unsigned int i = 0; i <= nSubPar; ++i) {
				message_queue *smq = new message_queue(open_only, toString(i).c_str());
				smq_.push_back(smq);
				//std::cout << "opening: " << std::toString(static_cast<long long int>(i)) << " with max size of " << smq_[i]->get_max_msg() << std::endl;
			}
		}
	}

	swarm_->commInit = true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, 0x50(%rdi)
movq 0x15c8(%rsi), %r13
subq 0x15c0(%rsi), %r13
shrq $0x3, %r13
imull 0x1620(%rsi), %r13d
cmpb $0x1, 0x1631(%rsi)
movq %rsi, %rdi
jne 0x6b497
leaq 0x1730(%r14), %rdi
leaq 0x86f47(%rip), %rsi     # 0xf23b0
callq 0x22250
testl %eax, %eax
je 0x6b70d
movl $0x1730, %edi           # imm = 0x1730
addq 0x50(%rbx), %rdi
leaq 0x86f19(%rip), %rsi     # 0xf239f
callq 0x22250
testl %eax, %eax
je 0x6b70d
movq 0x50(%rbx), %rdi
addq $0x1730, %rdi           # imm = 0x1730
leaq 0x86f07(%rip), %rsi     # 0xf23ac
callq 0x22250
testl %eax, %eax
je 0x6b7a4
incl %r13d
cmpb $0x1, 0x50(%r14)
jne 0x6b923
movq 0x10aae1(%rip), %rdi    # 0x175fa8
leaq 0x90329(%rip), %rsi     # 0xfb7f7
movl $0x27, %edx
callq 0x22ab0
leaq 0x68(%rbx), %rax
movq %rax, 0x40(%rsp)
xorl %r15d, %r15d
leaq 0xa8(%rsp), %rbp
leaq 0x88(%rsp), %r14
movl $0x20, %edi
callq 0x22980
movq %rax, %r12
leaq 0x58(%rsp), %rdi
movl %r15d, %esi
callq 0xbfa49
movq 0x58(%rsp), %rax
movl $0x1a4, 0x10(%rsp)      # imm = 0x1A4
movq %rax, 0xa8(%rsp)
movq $0x64, 0x88(%rsp)
movq $0x3e8, 0x90(%rsp) # imm = 0x3E8
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movl $0x190d0, %edx          # imm = 0x190D0
movq %r12, %rdi
movq %rbp, %rsi
movl $0x2, %ecx
xorl %r8d, %r8d
movq %r14, %r9
callq 0x6f774
movq %r12, 0x48(%rsp)
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x6b580
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x229c0
movq 0x70(%rbx), %rsi
cmpq 0x78(%rbx), %rsi
je 0x6b599
movq 0x48(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x70(%rbx)
jmp 0x6b5a8
movq 0x40(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x70ebc
incl %r15d
cmpl %r13d, %r15d
jbe 0x6b4f4
jmp 0x6b9ee
movq %rdx, 0x38(%rsp)
movq %rax, 0x8(%rsp)
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x6b5eb
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0x6b5eb
movq %rdx, 0x38(%rsp)
movq %rax, 0x8(%rsp)
movl $0x20, %esi
movq %r12, %rdi
callq 0x229c0
jmp 0x6b604
movq %rdx, 0x38(%rsp)
movq %rax, 0x8(%rsp)
cmpl $0x1, 0x38(%rsp)
jne 0x6bab7
movq 0x8(%rsp), %rdi
callq 0x22c00
leaq 0x58(%rsp), %rdi
movq %rax, %rsi
callq 0x6eb0a
movq 0x8(%rsp), %rdi
callq 0x22360
leaq 0x10(%rsp), %rdi
movl %r15d, %esi
callq 0xbfa49
movq 0x10(%rsp), %rdi
callq 0x70e16
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x6b663
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x229c0
movl $0x20, %edi
callq 0x22980
movq %rax, %r12
leaq 0x10(%rsp), %rdi
movl %r15d, %esi
callq 0xbfa49
movq 0x10(%rsp), %rax
movl $0x1a4, 0x54(%rsp)      # imm = 0x1A4
movq %rax, 0xb0(%rsp)
movq $0x64, 0x98(%rsp)
movq $0x3e8, 0xa0(%rsp) # imm = 0x3E8
leaq 0x54(%rsp), %rax
movq %rax, (%rsp)
movl $0x190d0, %edx          # imm = 0x190D0
movq %r12, %rdi
leaq 0xb0(%rsp), %rsi
movl $0x2, %ecx
xorl %r8d, %r8d
leaq 0x98(%rsp), %r9
callq 0x6f774
movq %r12, 0x48(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x6b6f9
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x229c0
leaq 0x58(%rsp), %rdi
callq 0x71514
callq 0x230b0
jmp 0x6b580
xorl %edi, %edi
xorl %esi, %esi
callq 0x22dd0
movq 0x10a84b(%rip), %rdi    # 0x175f68
leaq 0x58(%rsp), %rsi
callq 0x22b00
movq 0x50(%rbx), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x6b776
movq 0x10a86d(%rip), %r14    # 0x175fa8
leaq 0x90037(%rip), %rsi     # 0xfb779
movl $0x17, %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 0x10a7eb(%rip), %rdi    # 0x175f68
leaq 0x10(%rsp), %rsi
callq 0x22dc0
movq 0x50(%rbx), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x6b9ee
movq 0x10a809(%rip), %r14    # 0x175fa8
jmp 0x6b8e3
movq 0x50(%rbx), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x6b7f3
movq 0x10a7f0(%rip), %r14    # 0x175fa8
leaq 0x8ffed(%rip), %rsi     # 0xfb7ac
movl $0x25, %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
xorl %edi, %edi
xorl %esi, %esi
callq 0x22dd0
movq 0x10a765(%rip), %rdi    # 0x175f68
leaq 0x58(%rsp), %rsi
callq 0x22b00
movq 0x50(%rbx), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x6b85c
movq 0x10a787(%rip), %r14    # 0x175fa8
leaq 0x8ff51(%rip), %rsi     # 0xfb779
movl $0x17, %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 0x10a705(%rip), %rdi    # 0x175f68
leaq 0x10(%rsp), %rsi
callq 0x22dc0
movq 0x50(%rbx), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x6b9ee
movq 0x10a723(%rip), %r14    # 0x175fa8
leaq 0x8ff46(%rip), %rsi     # 0xfb7d2
movl $0xb, %edx
movq %r14, %rdi
callq 0x22ab0
movl 0x10(%rsp), %esi
movq %r14, %rdi
callq 0x231e0
movq %rax, %r15
leaq 0x8ff2f(%rip), %rsi     # 0xfb7de
movl $0x18, %edx
movq %rax, %rdi
callq 0x22ab0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq %r15, %rdi
callq 0x22050
movq %rax, %rdi
callq 0x22660
leaq 0x8fea7(%rip), %rsi     # 0xfb791
movl $0x1a, %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
jmp 0x6b9ee
movq 0x10a67e(%rip), %rdi    # 0x175fa8
leaq 0x8feee(%rip), %rsi     # 0xfb81f
movl $0x26, %edx
callq 0x22ab0
leaq 0x68(%rbx), %rax
movq %rax, 0x40(%rsp)
xorl %r12d, %r12d
leaq 0x98(%rsp), %rbp
leaq 0x10(%rsp), %r14
movl $0x20, %edi
callq 0x22980
movq %rax, %r15
leaq 0x58(%rsp), %rdi
movl %r12d, %esi
callq 0xbfa49
movq 0x58(%rsp), %rax
movq %rax, 0x98(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq %r15, %rdi
movq %rbp, %rsi
movl $0x2, %edx
xorl %ecx, %ecx
movq %r14, %r8
callq 0x70ff8
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x6b9b4
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x229c0
movq %r15, 0x88(%rsp)
movq 0x70(%rbx), %rsi
cmpq 0x78(%rbx), %rsi
je 0x6b9d0
movq %r15, (%rsi)
addq $0x8, 0x70(%rbx)
jmp 0x6b9e2
movq 0x40(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x70ebc
incl %r12d
cmpl %r13d, %r12d
jbe 0x6b954
movq 0x50(%rbx), %rax
movb $0x1, 0x13f8(%rax)
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x6ba33
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0x6ba33
movq %rax, 0x8(%rsp)
movl $0x20, %esi
movq %r12, %rdi
callq 0x229c0
jmp 0x6ba67
jmp 0x6ba62
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x6ba67
movq 0x20(%rsp), %rsi
incq %rsi
jmp 0x6ba3b
movq %rax, 0x8(%rsp)
leaq 0x58(%rsp), %rdi
callq 0x71514
callq 0x230b0
jmp 0x6bab7
jmp 0x6ba7a
movq %rax, %rdi
callq 0x3185b
movq %rax, 0x8(%rsp)
jmp 0x6baaa
movq %rax, 0x8(%rsp)
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x6baaa
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x229c0
movl $0x20, %esi
movq %r15, %rdi
callq 0x229c0
movq 0x8(%rsp), %rdi
callq 0x23240
nop