// File: /workspace/github_cpp_makefile_star2_O2/richardposner[P]BioNetFit2/src/code/Swarm.cpp
// Function: Swarm::generateSlurmBatchFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
string Swarm::generateSlurmBatchFile(string runCmd) {
	string sbatchPath = options.jobOutputDir + "slurm_script.sh";
	ofstream sbatch(sbatchPath, ios::out);

	if (sbatch.is_open()) {
		//TODO: Need to display terminal output from cluster jobs

		sbatch << "#!/bin/sh" << endl << endl;

		// Add the job name
		sbatch << "#SBATCH -J " + options.jobName << endl;

		// Specify the cluster account if needed
		if (!options.clusterAccount.empty()) {
			sbatch << "#SBATCH -A " + options.clusterAccount << endl;
		}

		if (!options.clusterQueue.empty()) {
			sbatch << "#SBATCH -p " + options.clusterQueue << endl;
		}

		// Specify output directory if needed
		if (options.saveClusterOutput) {
			sbatch << "#SBATCH -o " + options.outputDir + "/" + options.jobName + "_cluster_output/" + options.jobName << endl;
		}
		else {
			sbatch << "#SBATCH -o /dev/null" << endl;
		}

		sbatch << "#SBATCH -n" + toString(options.parallelCount + 1) << endl;

		sbatch << endl;

		sbatch << "module load openmpi" << endl;
		//sbatch << "module load intel << endl;"
		sbatch << "echo LD_LIBRARY_PATH: $LD_LIBRARY_PATH" << endl;
		sbatch << "echo PATH: $PATH" << endl;
		sbatch << "echo which mpirun:" << endl;
		sbatch << "which mpirun" << endl;
		sbatch << "echo pwd:" << endl;
		sbatch << "pwd"	<< endl;
		sbatch << "echo ldd GenFit2:" << endl;
		sbatch << "ldd /home/bt285/BioNetFit/bin/GenFit2" << endl;;

		cout<<"Swarm::generateSlurmBatchFile Might need some modifications ....582\n";
		sbatch << "mpirun -mca mca_component_show_load_errors 10 -v --tag-output -np 1 " << runCmd << " load " << sConf_[0] << " : -np " << options.swarmSize << " " << runCmd << " particle 0 run " << sConf_[0] << endl;

		sbatch.close();
	}
	else {
		outputError("Error: Couldn't generate slurm batch file: " + sbatchPath + ". Quitting.");
	}

	runCmd = "sbatch " + sbatchPath;

	return runCmd;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x2e8, %rsp            # imm = 0x2E8
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
addq $0x1520, %rsi           # imm = 0x1520
leaq 0x60242(%rip), %rdx     # 0xde5d1
leaq 0x48(%rsp), %r12
movq %r12, %rdi
callq 0x334ed
leaq 0xe8(%rsp), %rdi
pushq $0x10
popq %rdx
movq %r12, %rsi
callq 0x294c0
leaq 0x158(%rsp), %rdi
callq 0x28200
testb %al, %al
je 0x7e822
leaq 0x60216(%rip), %rsi     # 0xde5e1
leaq 0xe8(%rsp), %rdi
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
movq %rax, %rdi
callq 0x284a0
leaq 0x14c0(%r15), %r12
leaq 0x601f5(%rip), %rsi     # 0xde5eb
leaq 0x8(%rsp), %rdi
movq %r12, %rdx
callq 0x3338b
leaq 0xe8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x28910
movq %rax, %rdi
callq 0x284a0
leaq 0x8(%rsp), %rdi
callq 0x295a0
cmpq $0x0, 0x1758(%r15)
je 0x7e46d
leaq 0x1750(%r15), %rdx
leaq 0x601b8(%rip), %rsi     # 0xde5f7
leaq 0x8(%rsp), %rdi
callq 0x3338b
leaq 0xe8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x28910
movq %rax, %rdi
callq 0x284a0
leaq 0x8(%rsp), %rdi
callq 0x295a0
cmpq $0x0, 0x1780(%r15)
je 0x7e4b3
leaq 0x1778(%r15), %rdx
leaq 0x6017e(%rip), %rsi     # 0xde603
leaq 0x8(%rsp), %rdi
callq 0x3338b
leaq 0xe8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x28910
movq %rax, %rdi
callq 0x284a0
leaq 0x8(%rsp), %rdi
callq 0x295a0
cmpb $0x1, 0x1770(%r15)
jne 0x7e589
leaq 0x1500(%r15), %rdx
leaq 0x60140(%rip), %rsi     # 0xde60f
leaq 0x68(%rsp), %rdi
callq 0x3338b
leaq 0x5f4d7(%rip), %rdx     # 0xdd9b7
leaq 0x88(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x3336c
leaq 0xa8(%rsp), %rdi
leaq 0x88(%rsp), %rsi
movq %r12, %rdx
callq 0x334ce
leaq 0x5fec0(%rip), %rdx     # 0xde3d1
leaq 0x28(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x3336c
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
movq %r12, %rdx
callq 0x334ce
leaq 0xe8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x28910
movq %rax, %rdi
callq 0x284a0
leaq 0x8(%rsp), %rdi
callq 0x295a0
leaq 0x28(%rsp), %rdi
callq 0x295a0
leaq 0xa8(%rsp), %rdi
callq 0x295a0
leaq 0x88(%rsp), %rdi
callq 0x295a0
leaq 0x68(%rsp), %rdi
callq 0x295a0
jmp 0x7e5a5
leaq 0x6008b(%rip), %rsi     # 0xde61b
leaq 0xe8(%rsp), %rdi
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
movl 0x1628(%r15), %esi
incl %esi
leaq 0x28(%rsp), %rdi
callq 0x9f56b
leaq 0x60071(%rip), %rsi     # 0xde630
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x4933b
leaq 0xe8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x28910
movq %rax, %rdi
callq 0x284a0
leaq 0x8(%rsp), %rdi
callq 0x295a0
leaq 0x28(%rsp), %rdi
callq 0x295a0
leaq 0xe8(%rsp), %rdi
callq 0x284a0
leaq 0x6002b(%rip), %rsi     # 0xde63b
leaq 0xe8(%rsp), %rdi
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
leaq 0x60023(%rip), %rsi     # 0xde64f
leaq 0xe8(%rsp), %rdi
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
leaq 0x6002e(%rip), %rsi     # 0xde676
leaq 0xe8(%rsp), %rdi
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
leaq 0x60023(%rip), %rsi     # 0xde687
leaq 0xe8(%rsp), %rdi
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
leaq 0x5f57d(%rip), %rsi     # 0xddbfd
leaq 0xe8(%rsp), %rdi
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
leaq 0x5fffe(%rip), %rsi     # 0xde69a
leaq 0xe8(%rsp), %rdi
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
leaq 0x5ffec(%rip), %rsi     # 0xde6a4
leaq 0xe8(%rsp), %rdi
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
leaq 0x5ffd4(%rip), %rsi     # 0xde6a8
leaq 0xe8(%rsp), %rdi
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
leaq 0x5ffca(%rip), %rsi     # 0xde6ba
leaq 0xe8(%rsp), %rdi
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
movq 0xe788c(%rip), %rdi     # 0x165f98
leaq 0x5ffcd(%rip), %rsi     # 0xde6e0
callq 0x289f0
leaq 0x60006(%rip), %rsi     # 0xde725
leaq 0xe8(%rsp), %rdi
callq 0x289f0
movq %rax, %rdi
movq %r14, %rsi
callq 0x28910
leaq 0x5fe49(%rip), %rsi     # 0xde587
movq %rax, %rdi
callq 0x289f0
movq 0x1938(%r15), %rsi
movq %rax, %rdi
callq 0x28910
leaq 0x6000e(%rip), %rsi     # 0xde76a
movq %rax, %rdi
callq 0x289f0
movl 0x1620(%r15), %esi
movq %rax, %rdi
callq 0x29290
leaq 0x60e93(%rip), %rsi     # 0xdf60d
movq %rax, %rdi
callq 0x289f0
movq %rax, %rdi
movq %r14, %rsi
callq 0x28910
leaq 0x5ffde(%rip), %rsi     # 0xde772
movq %rax, %rdi
callq 0x289f0
movq 0x1938(%r15), %rsi
movq %rax, %rdi
callq 0x28910
movq %rax, %rdi
callq 0x284a0
leaq 0xe8(%rsp), %rdi
callq 0x28e60
leaq 0x5ffe8(%rip), %rsi     # 0xde7af
leaq 0x8(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x3338b
leaq 0x8(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x28c40
movq %r15, %rdi
callq 0x295a0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x28d00
leaq 0xe8(%rsp), %rdi
callq 0x28f10
leaq 0x48(%rsp), %rdi
callq 0x295a0
movq %rbx, %rax
addq $0x2e8, %rsp            # imm = 0x2E8
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x5ff5a(%rip), %rsi     # 0xde783
leaq 0x8(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x3338b
leaq 0x61363(%rip), %rdx     # 0xdfba2
leaq 0xc8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x3336c
leaq 0xc8(%rsp), %rsi
movq %r15, %rdi
callq 0x6aed2
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x295a0
jmp 0x7e8f7
jmp 0x7e8f4
movq %rax, %rbx
jmp 0x7e8a8
movq %rax, %rbx
jmp 0x7e8b2
movq %rax, %rbx
jmp 0x7e8bf
movq %rax, %rbx
jmp 0x7e8cc
jmp 0x7e903
jmp 0x7e903
jmp 0x7e903
jmp 0x7e903
jmp 0x7e903
movq %rax, %rbx
jmp 0x7e8ed
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x295a0
leaq 0x28(%rsp), %rdi
callq 0x295a0
leaq 0xa8(%rsp), %rdi
callq 0x295a0
leaq 0x88(%rsp), %rdi
callq 0x295a0
leaq 0x68(%rsp), %rdi
jmp 0x7e8fc
jmp 0x7e903
jmp 0x7e903
movq %rax, %rbx
jmp 0x7e913
jmp 0x7e8f4
jmp 0x7e8f4
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x295a0
leaq 0x28(%rsp), %rdi
jmp 0x7e8fc
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x295a0
jmp 0x7e906
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x28f10
leaq 0x48(%rsp), %rdi
callq 0x295a0
movq %rbx, %rdi
callq 0x292f0
nop