Created
June 25, 2012 10:19
-
-
Save andre-merzky/2987818 to your computer and use it in GitHub Desktop.
SAGA-C++ example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<saga/saga.hpp> | |
void work (int jobno, saga::session s, saga::job::service js) | |
{ | |
saga::url bfast_base_dir ("sftp://india.futuregrid.org/N/u/oweidner/software/bfast/"); | |
try | |
{ | |
std::stringstream ss; | |
ss << jobno; | |
std::string id = ss.str (); | |
std::string workdir = bfast_base_dir.get_path () + "/tmp/run/" + id; | |
saga::filesystem::directory basedir (s, bfast_base_dir); | |
basedir.make_dir (workdir); | |
saga.job.Description jd; | |
jd.set_attribute (saga::job::executable, "$BFAST_DIR/bin/bfast"); | |
jd.set_attribute (saga::job::working _directory, workdir); | |
jd.set_attribute (saga::job::description_cpu_count, "1"); | |
jd.set_attribute (saga::job::description_wall_time_limit, "5"); | |
std::vector vec; | |
vec.push_back ("BFAST_DIR=" + bfast_base_dir.get_path ()); | |
jd.set_vector_attribute (saga::job::description_environment, vec); | |
vec.clear (); | |
vec.push_back ("match"); | |
vec.push_back ("-A 1"); | |
vec.push_back ("-r $BFAST_DIR/data/small/reads_5K/reads.10.fastq"); | |
vec.push_back ("-f $BFAST_DIR/data/small/reference/hg_2122.fa"); | |
jd.set_vector_attribute (saga::job::description_arguments, vec); | |
saga::job::job myjob = js.create_job (jd) | |
myjob.run() | |
std::cout << "Job #" << jobno << " started with ID " << myjob.get_jobid () | |
<< "and working directory: " << workdir << std::endl; | |
myjob.wait() | |
std::cout << "Job #" << jobno << " with ID " << myjob.get_jobid () | |
<< " finished (RC: " << myjob.get_attribute ("Exitcode") | |
<< ". Output available in: " << workdir << std::endl; | |
basedir.close(); | |
} | |
catch ( const saga::exception & ex ) | |
{ | |
std::cerr << "An error occurred during job execution: " % | |
<< ex.get_message () << std::endl; | |
exit (-1); | |
} | |
} | |
int main () | |
{ | |
saga::url execution_host ("pbs+ssh://india.futuregrid.org"); | |
saga.context ctx; | |
ctx.set_attribute ("type" = "ssh"); | |
ctx.set_attribute ("userid" = "oweidner"); // like 'ssh username@host ...' | |
ctx.set_attribute ("userkey" = "/Users/oweidner/.ssh/rsa_work"); // like ssh -i ...' | |
saga.session session; | |
session.add_context (ctx); | |
saga.job.service js (s, execution_host); | |
for ( unsigned int i = 0; i < 4; i++ ) | |
{ | |
work (i, session, js); | |
} | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<saga/saga.hpp> | |
void work (int jobno, saga::session s, saga::job::service js) | |
{ | |
saga::url bfast_base_dir ("sftp://india.futuregrid.org/N/u/oweidner/software/bfast/"); | |
try | |
{ | |
std::stringstream ss; | |
ss << jobno; | |
std::string id = ss.str (); | |
std::string workdir = bfast_base_dir.get_path () + "/tmp/run/" + id; | |
saga::filesystem::directory basedir (s, bfast_base_dir); | |
basedir.make_dir (workdir); | |
saga.job.Description jd; | |
jd.set_attribute (saga::job::executable, "$BFAST_DIR/bin/bfast"); | |
jd.set_attribute (saga::job::working _directory, workdir); | |
jd.set_attribute (saga::job::description_cpu_count, "1"); | |
jd.set_attribute (saga::job::description_wall_time_limit, "5"); | |
std::vector vec; | |
vec.push_back ("BFAST_DIR=" + bfast_base_dir.get_path ()); | |
jd.set_vector_attribute (saga::job::description_environment, vec); | |
vec.clear (); | |
vec.push_back ("match"); | |
vec.push_back ("-A 1"); | |
vec.push_back ("-r $BFAST_DIR/data/small/reads_5K/reads.10.fastq"); | |
vec.push_back ("-f $BFAST_DIR/data/small/reference/hg_2122.fa"); | |
jd.set_vector_attribute (saga::job::description_arguments, vec); | |
saga::job::job myjob = js.create_job (jd) | |
myjob.run() | |
std::cout << "Job #" << jobno << " started with ID " << myjob.get_jobid () | |
<< "and working directory: " << workdir << std::endl; | |
myjob.wait() | |
std::cout << "Job #" << jobno << " with ID " << myjob.get_jobid () | |
<< " finished (RC: " << myjob.get_attribute ("Exitcode") | |
<< ". Output available in: " << workdir << std::endl; | |
basedir.close(); | |
} | |
catch ( const saga::exception & ex ) | |
{ | |
std::cerr << "An error occurred during job execution: " % | |
<< ex.get_message () << std::endl; | |
exit (-1); | |
} | |
} | |
int main () | |
{ | |
saga::url execution_host ("pbs+ssh://india.futuregrid.org"); | |
saga.context ctx; | |
ctx.set_attribute ("type" , "ssh"); | |
ctx.set_attribute ("userid" , "oweidner"); // like 'ssh username@host ...' | |
ctx.set_attribute ("userkey", "/Users/oweidner/.ssh/rsa_work"); // like ssh -i ...' | |
saga.session session; | |
session.add_context (ctx); | |
saga.job.service js (s, execution_host); | |
for ( unsigned int i = 0; i < 4; i++ ) | |
{ | |
work (i, session, js); | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment