// File: /workspace/github_cpp_makefile_star2_O1/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)
jne 0x6b984
leaq 0x1730(%r14), %rdi
leaq 0x86a76(%rip), %rsi     # 0xf23d0
callq 0x22250
testl %eax, %eax
je 0x6bbfc
movl $0x1730, %edi           # imm = 0x1730
addq 0x50(%rbx), %rdi
leaq 0x86a48(%rip), %rsi     # 0xf23bf
callq 0x22250
testl %eax, %eax
je 0x6bbfc
movl $0x1730, %edi           # imm = 0x1730
addq 0x50(%rbx), %rdi
leaq 0x86a38(%rip), %rsi     # 0xf23cc
callq 0x22250
testl %eax, %eax
je 0x6bc93
incl %r13d
cmpb $0x1, 0x50(%r14)
jne 0x6be12
movq 0x10a5da(%rip), %rdi    # 0x175f90
leaq 0x8fe5a(%rip), %rsi     # 0xfb817
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 0xc03b8
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 0x6fc8a
movq %r12, 0x48(%rsp)
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x6ba6f
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x229c0
movq 0x70(%rbx), %rsi
cmpq 0x78(%rbx), %rsi
je 0x6ba88
movq 0x48(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x70(%rbx)
jmp 0x6ba97
movq 0x40(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x7145a
incl %r15d
cmpl %r13d, %r15d
jbe 0x6b9e3
jmp 0x6bedd
movq %rdx, 0x38(%rsp)
movq %rax, 0x8(%rsp)
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x6bada
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0x6bada
movq %rdx, 0x38(%rsp)
movq %rax, 0x8(%rsp)
movl $0x20, %esi
movq %r12, %rdi
callq 0x229c0
jmp 0x6baf3
movq %rdx, 0x38(%rsp)
movq %rax, 0x8(%rsp)
cmpl $0x1, 0x38(%rsp)
jne 0x6bfa6
movq 0x8(%rsp), %rdi
callq 0x22c00
leaq 0x58(%rsp), %rdi
movq %rax, %rsi
callq 0x6f024
movq 0x8(%rsp), %rdi
callq 0x22360
leaq 0x10(%rsp), %rdi
movl %r15d, %esi
callq 0xc03b8
movq 0x10(%rsp), %rdi
callq 0x713b4
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x6bb52
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x229c0
movl $0x20, %edi
callq 0x22980
movq %rax, %r12
leaq 0x10(%rsp), %rdi
movl %r15d, %esi
callq 0xc03b8
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 0x6fc8a
movq %r12, 0x48(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x6bbe8
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x229c0
leaq 0x58(%rsp), %rdi
callq 0x71abe
callq 0x230b0
jmp 0x6ba6f
xorl %edi, %edi
xorl %esi, %esi
callq 0x22dd0
movq 0x10a344(%rip), %rdi    # 0x175f50
leaq 0x58(%rsp), %rsi
callq 0x22b00
movq 0x50(%rbx), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x6bc65
movq 0x10a366(%rip), %r14    # 0x175f90
leaq 0x8fb68(%rip), %rsi     # 0xfb799
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 0x10a2e4(%rip), %rdi    # 0x175f50
leaq 0x10(%rsp), %rsi
callq 0x22dc0
movq 0x50(%rbx), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x6bedd
movq 0x10a302(%rip), %r14    # 0x175f90
jmp 0x6bdd2
movq 0x50(%rbx), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x6bce2
movq 0x10a2e9(%rip), %r14    # 0x175f90
leaq 0x8fb1e(%rip), %rsi     # 0xfb7cc
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 0x10a25e(%rip), %rdi    # 0x175f50
leaq 0x58(%rsp), %rsi
callq 0x22b00
movq 0x50(%rbx), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x6bd4b
movq 0x10a280(%rip), %r14    # 0x175f90
leaq 0x8fa82(%rip), %rsi     # 0xfb799
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 0x10a1fe(%rip), %rdi    # 0x175f50
leaq 0x10(%rsp), %rsi
callq 0x22dc0
movq 0x50(%rbx), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x6bedd
movq 0x10a21c(%rip), %r14    # 0x175f90
leaq 0x8fa77(%rip), %rsi     # 0xfb7f2
movl $0xb, %edx
movq %r14, %rdi
callq 0x22ab0
movl 0x10(%rsp), %esi
movq %r14, %rdi
callq 0x231e0
movq %rax, %r15
leaq 0x8fa60(%rip), %rsi     # 0xfb7fe
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 0x8f9d8(%rip), %rsi     # 0xfb7b1
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 0x6bedd
movq 0x10a177(%rip), %rdi    # 0x175f90
leaq 0x8fa1f(%rip), %rsi     # 0xfb83f
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 0xc03b8
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 0x71596
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x6bea3
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x229c0
movq %r15, 0x88(%rsp)
movq 0x70(%rbx), %rsi
cmpq 0x78(%rbx), %rsi
je 0x6bebf
movq %r15, (%rsi)
addq $0x8, 0x70(%rbx)
jmp 0x6bed1
movq 0x40(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x7145a
incl %r12d
cmpl %r13d, %r12d
jbe 0x6be43
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 0x6bf22
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0x6bf22
movq %rax, 0x8(%rsp)
movl $0x20, %esi
movq %r12, %rdi
callq 0x229c0
jmp 0x6bf56
jmp 0x6bf51
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x6bf56
movq 0x20(%rsp), %rsi
incq %rsi
jmp 0x6bf2a
movq %rax, 0x8(%rsp)
leaq 0x58(%rsp), %rdi
callq 0x71abe
callq 0x230b0
jmp 0x6bfa6
jmp 0x6bf69
movq %rax, %rdi
callq 0x318ef
movq %rax, 0x8(%rsp)
jmp 0x6bf99
movq %rax, 0x8(%rsp)
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x6bf99
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x229c0
movl $0x20, %esi
movq %r15, %rdi
callq 0x229c0
movq 0x8(%rsp), %rdi
callq 0x23240