// File: 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 %rbp
movq %rsp, %rbp
subq $0x4f0, %rsp            # imm = 0x4F0
movq %rdx, -0x410(%rbp)
movq %rdi, -0x408(%rbp)
movq %rdi, %rax
movq %rax, -0x400(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rsi
movq %rsi, -0x3f8(%rbp)
addq $0x1520, %rsi           # imm = 0x1520
leaq 0xd4b88(%rip), %rdx     # 0x1e2fe0
leaq -0x38(%rbp), %rdi
movq %rdi, -0x3f0(%rbp)
callq 0x447b0
movq -0x3f0(%rbp), %rsi
leaq -0x238(%rbp), %rdi
movl $0x10, %edx
callq 0x2f360
jmp 0x10e482
leaq -0x238(%rbp), %rdi
callq 0x30530
movb %al, -0x411(%rbp)
jmp 0x10e496
movb -0x411(%rbp), %al
testb $0x1, %al
jne 0x10e4a5
jmp 0x10ed02
leaq 0xd4b44(%rip), %rsi     # 0x1e2ff0
leaq -0x238(%rbp), %rdi
callq 0x2ff50
movq %rax, -0x420(%rbp)
jmp 0x10e4c1
movq -0x420(%rbp), %rdi
movq 0x1c6af9(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
movq %rax, -0x428(%rbp)
jmp 0x10e4dd
movq -0x428(%rbp), %rdi
movq 0x1c6add(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10e4f2
movq -0x3f8(%rbp), %rdx
addq $0x14c0, %rdx           # imm = 0x14C0
leaq 0xd4af3(%rip), %rsi     # 0x1e2ffa
leaq -0x268(%rbp), %rdi
callq 0x44240
jmp 0x10e515
leaq -0x238(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x2f780
movq %rax, -0x430(%rbp)
jmp 0x10e531
movq -0x430(%rbp), %rdi
movq 0x1c6a89(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10e546
leaq -0x268(%rbp), %rdi
callq 0x311e8
movq -0x3f8(%rbp), %rdi
addq $0x14c0, %rdi           # imm = 0x14C0
addq $0x290, %rdi            # imm = 0x290
callq 0x2f700
testb $0x1, %al
jne 0x10e64a
movq -0x3f8(%rbp), %rdx
addq $0x1750, %rdx           # imm = 0x1750
leaq 0xd4a7d(%rip), %rsi     # 0x1e3006
leaq -0x288(%rbp), %rdi
callq 0x44240
jmp 0x10e597
leaq -0x238(%rbp), %rdi
leaq -0x288(%rbp), %rsi
callq 0x2f780
movq %rax, -0x438(%rbp)
jmp 0x10e5b3
movq -0x438(%rbp), %rdi
movq 0x1c6a07(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10e5c8
leaq -0x288(%rbp), %rdi
callq 0x311e8
jmp 0x10e64a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x10ee22
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x10ee16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x311e8
jmp 0x10ee16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
leaq -0x288(%rbp), %rdi
callq 0x311e8
jmp 0x10ee16
movq -0x3f8(%rbp), %rdi
addq $0x14c0, %rdi           # imm = 0x14C0
addq $0x2b8, %rdi            # imm = 0x2B8
callq 0x2f700
testb $0x1, %al
jne 0x10e6f1
movq -0x3f8(%rbp), %rdx
addq $0x1778, %rdx           # imm = 0x1778
leaq 0xd4991(%rip), %rsi     # 0x1e3012
leaq -0x2a8(%rbp), %rdi
callq 0x44240
jmp 0x10e68f
leaq -0x238(%rbp), %rdi
leaq -0x2a8(%rbp), %rsi
callq 0x2f780
movq %rax, -0x440(%rbp)
jmp 0x10e6ab
movq -0x440(%rbp), %rdi
movq 0x1c690f(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10e6c0
leaq -0x2a8(%rbp), %rdi
callq 0x311e8
jmp 0x10e6f1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
leaq -0x2a8(%rbp), %rdi
callq 0x311e8
jmp 0x10ee16
movq -0x3f8(%rbp), %rax
testb $0x1, 0x1770(%rax)
je 0x10e8bb
movq -0x3f8(%rbp), %rdx
addq $0x1500, %rdx           # imm = 0x1500
leaq 0xd4904(%rip), %rsi     # 0x1e301e
leaq -0x348(%rbp), %rdi
callq 0x44240
jmp 0x10e728
leaq 0xd3c24(%rip), %rdx     # 0x1e2353
leaq -0x328(%rbp), %rdi
leaq -0x348(%rbp), %rsi
callq 0x441f0
jmp 0x10e744
movq -0x3f8(%rbp), %rdx
addq $0x14c0, %rdx           # imm = 0x14C0
leaq -0x308(%rbp), %rdi
leaq -0x328(%rbp), %rsi
callq 0x44760
jmp 0x10e767
leaq 0xd4672(%rip), %rdx     # 0x1e2de0
leaq -0x2e8(%rbp), %rdi
leaq -0x308(%rbp), %rsi
callq 0x441f0
jmp 0x10e783
movq -0x3f8(%rbp), %rdx
addq $0x14c0, %rdx           # imm = 0x14C0
leaq -0x2c8(%rbp), %rdi
leaq -0x2e8(%rbp), %rsi
callq 0x44760
jmp 0x10e7a6
leaq -0x238(%rbp), %rdi
leaq -0x2c8(%rbp), %rsi
callq 0x2f780
movq %rax, -0x448(%rbp)
jmp 0x10e7c2
movq -0x448(%rbp), %rdi
movq 0x1c67f8(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10e7d7
leaq -0x2c8(%rbp), %rdi
callq 0x311e8
leaq -0x2e8(%rbp), %rdi
callq 0x311e8
leaq -0x308(%rbp), %rdi
callq 0x311e8
leaq -0x328(%rbp), %rdi
callq 0x311e8
leaq -0x348(%rbp), %rdi
callq 0x311e8
jmp 0x10e8ee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x10e8aa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x10e89e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x10e892
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x10e886
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
leaq -0x2c8(%rbp), %rdi
callq 0x311e8
leaq -0x2e8(%rbp), %rdi
callq 0x311e8
leaq -0x308(%rbp), %rdi
callq 0x311e8
leaq -0x328(%rbp), %rdi
callq 0x311e8
leaq -0x348(%rbp), %rdi
callq 0x311e8
jmp 0x10ee16
leaq 0xd4768(%rip), %rsi     # 0x1e302a
leaq -0x238(%rbp), %rdi
callq 0x2ff50
movq %rax, -0x450(%rbp)
jmp 0x10e8d7
movq -0x450(%rbp), %rdi
movq 0x1c66e3(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10e8ec
jmp 0x10e8ee
movq -0x3f8(%rbp), %rax
movl 0x1628(%rax), %esi
incl %esi
leaq -0x388(%rbp), %rdi
callq 0x17e460
jmp 0x10e90b
leaq 0xd472d(%rip), %rsi     # 0x1e303f
leaq -0x368(%rbp), %rdi
leaq -0x388(%rbp), %rdx
callq 0x8e0f0
jmp 0x10e927
leaq -0x238(%rbp), %rdi
leaq -0x368(%rbp), %rsi
callq 0x2f780
movq %rax, -0x458(%rbp)
jmp 0x10e943
movq -0x458(%rbp), %rdi
movq 0x1c6677(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10e958
leaq -0x368(%rbp), %rdi
callq 0x311e8
leaq -0x388(%rbp), %rdi
callq 0x311e8
movq 0x1c6651(%rip), %rsi    # 0x2d4fc8
leaq -0x238(%rbp), %rdi
callq 0x30c10
jmp 0x10e985
leaq 0xd46be(%rip), %rsi     # 0x1e304a
leaq -0x238(%rbp), %rdi
callq 0x2ff50
movq %rax, -0x460(%rbp)
jmp 0x10e9a1
movq -0x460(%rbp), %rdi
movq 0x1c6619(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10e9b6
leaq 0xd46a1(%rip), %rsi     # 0x1e305e
leaq -0x238(%rbp), %rdi
callq 0x2ff50
movq %rax, -0x468(%rbp)
jmp 0x10e9d2
movq -0x468(%rbp), %rdi
movq 0x1c65e8(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10e9e7
leaq 0xd4697(%rip), %rsi     # 0x1e3085
leaq -0x238(%rbp), %rdi
callq 0x2ff50
movq %rax, -0x470(%rbp)
jmp 0x10ea03
movq -0x470(%rbp), %rdi
movq 0x1c65b7(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10ea18
leaq 0xd4677(%rip), %rsi     # 0x1e3096
leaq -0x238(%rbp), %rdi
callq 0x2ff50
movq %rax, -0x478(%rbp)
jmp 0x10ea34
movq -0x478(%rbp), %rdi
movq 0x1c6586(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10ea49
leaq 0xd3bbc(%rip), %rsi     # 0x1e260c
leaq -0x238(%rbp), %rdi
callq 0x2ff50
movq %rax, -0x480(%rbp)
jmp 0x10ea65
movq -0x480(%rbp), %rdi
movq 0x1c6555(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10ea7a
leaq 0xd4628(%rip), %rsi     # 0x1e30a9
leaq -0x238(%rbp), %rdi
callq 0x2ff50
movq %rax, -0x488(%rbp)
jmp 0x10ea96
movq -0x488(%rbp), %rdi
movq 0x1c6524(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10eaab
leaq 0xd4601(%rip), %rsi     # 0x1e30b3
leaq -0x238(%rbp), %rdi
callq 0x2ff50
movq %rax, -0x490(%rbp)
jmp 0x10eac7
movq -0x490(%rbp), %rdi
movq 0x1c64f3(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10eadc
leaq 0xd45d4(%rip), %rsi     # 0x1e30b7
leaq -0x238(%rbp), %rdi
callq 0x2ff50
movq %rax, -0x498(%rbp)
jmp 0x10eaf8
movq -0x498(%rbp), %rdi
movq 0x1c64c2(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10eb0d
leaq 0xd45b5(%rip), %rsi     # 0x1e30c9
leaq -0x238(%rbp), %rdi
callq 0x2ff50
movq %rax, -0x4a0(%rbp)
jmp 0x10eb29
movq -0x4a0(%rbp), %rdi
movq 0x1c6491(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10eb3e
movq 0x1c640b(%rip), %rdi    # 0x2d4f50
leaq 0xd45a3(%rip), %rsi     # 0x1e30ef
callq 0x2ff50
jmp 0x10eb53
leaq 0xd45da(%rip), %rsi     # 0x1e3134
leaq -0x238(%rbp), %rdi
callq 0x2ff50
movq %rax, -0x4a8(%rbp)
jmp 0x10eb6f
movq -0x410(%rbp), %rsi
movq -0x4a8(%rbp), %rdi
callq 0x2f780
movq %rax, -0x4b0(%rbp)
jmp 0x10eb8b
movq -0x4b0(%rbp), %rdi
leaq 0xd43fd(%rip), %rsi     # 0x1e2f96
callq 0x2ff50
movq %rax, -0x4b8(%rbp)
jmp 0x10eba7
movq -0x3f8(%rbp), %rdi
addq $0x1938, %rdi           # imm = 0x1938
xorl %eax, %eax
movl %eax, %esi
callq 0x449e0
movq -0x4b8(%rbp), %rdi
movq %rax, %rsi
callq 0x2f780
movq %rax, -0x4c0(%rbp)
jmp 0x10ebd6
movq -0x4c0(%rbp), %rdi
leaq 0xd4595(%rip), %rsi     # 0x1e3179
callq 0x2ff50
movq %rax, -0x4c8(%rbp)
jmp 0x10ebf2
movq -0x4c8(%rbp), %rdi
movq -0x3f8(%rbp), %rax
movl 0x1620(%rax), %esi
callq 0x2f800
movq %rax, -0x4d0(%rbp)
jmp 0x10ec14
movq -0x4d0(%rbp), %rdi
leaq 0xd54ad(%rip), %rsi     # 0x1e40cf
callq 0x2ff50
movq %rax, -0x4d8(%rbp)
jmp 0x10ec30
movq -0x410(%rbp), %rsi
movq -0x4d8(%rbp), %rdi
callq 0x2f780
movq %rax, -0x4e0(%rbp)
jmp 0x10ec4c
movq -0x4e0(%rbp), %rdi
leaq 0xd4527(%rip), %rsi     # 0x1e3181
callq 0x2ff50
movq %rax, -0x4e8(%rbp)
jmp 0x10ec68
movq -0x3f8(%rbp), %rdi
addq $0x1938, %rdi           # imm = 0x1938
xorl %eax, %eax
movl %eax, %esi
callq 0x449e0
movq -0x4e8(%rbp), %rdi
movq %rax, %rsi
callq 0x2f780
movq %rax, -0x4f0(%rbp)
jmp 0x10ec97
movq -0x4f0(%rbp), %rdi
movq 0x1c6323(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10ecac
leaq -0x238(%rbp), %rdi
callq 0x30910
jmp 0x10ecba
jmp 0x10eda6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x10ecf1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
leaq -0x368(%rbp), %rdi
callq 0x311e8
leaq -0x388(%rbp), %rdi
callq 0x311e8
jmp 0x10ee16
leaq 0xd4489(%rip), %rsi     # 0x1e3192
leaq -0x3c8(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq 0x44240
jmp 0x10ed1b
leaq 0xd5942(%rip), %rdx     # 0x1e4664
leaq -0x3a8(%rbp), %rdi
leaq -0x3c8(%rbp), %rsi
callq 0x441f0
jmp 0x10ed37
movq -0x3f8(%rbp), %rdi
leaq -0x3a8(%rbp), %rsi
callq 0xeada0
jmp 0x10ed4c
leaq -0x3a8(%rbp), %rdi
callq 0x311e8
leaq -0x3c8(%rbp), %rdi
callq 0x311e8
jmp 0x10eda6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x10ed98
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
leaq -0x3a8(%rbp), %rdi
callq 0x311e8
leaq -0x3c8(%rbp), %rdi
callq 0x311e8
jmp 0x10ee16
leaq 0xd4411(%rip), %rsi     # 0x1e31be
leaq -0x3e8(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq 0x44240
jmp 0x10edbf
movq -0x410(%rbp), %rdi
leaq -0x3e8(%rbp), %rsi
callq 0x2fd80
leaq -0x3e8(%rbp), %rdi
callq 0x311e8
movq -0x408(%rbp), %rdi
movq -0x410(%rbp), %rsi
callq 0x30940
leaq -0x238(%rbp), %rdi
callq 0x304f0
leaq -0x38(%rbp), %rdi
callq 0x311e8
movq -0x400(%rbp), %rax
addq $0x4f0, %rsp            # imm = 0x4F0
popq %rbp
retq
leaq -0x238(%rbp), %rdi
callq 0x304f0
leaq -0x38(%rbp), %rdi
callq 0x311e8
movq -0x240(%rbp), %rdi
callq 0x30170
nopw (%rax,%rax)