Beispiel #1
0
drmaa2_list drmaa2_list_create_copy(drmaa2_list l, const drmaa2_list_entryfree callback, const drmaa2_copy_data_callback copy)
{
    //the user is responsible for setting appropriate copy and free callbacks
    if (l == NULL)
        return DRMAA2_UNSET_LIST;

    drmaa2_list list = drmaa2_list_create(l->type, callback);
    
    drmaa2_list_item current_item, new_item;
    drmaa2_list_item *p_to_set;
    current_item = l->head;
    p_to_set = (drmaa2_list_item*)&(list->head);
    while (current_item != NULL)
    {
        new_item = (drmaa2_list_item)malloc(sizeof(drmaa2_list_item));
        *p_to_set = new_item;
        //make flat copy in case that no copy callback is set
        new_item->data = (copy != NULL) ? copy(current_item->data) : current_item->data;

        current_item = current_item->next;
        p_to_set = &(new_item->next);
    }
    new_item = NULL;
    list->size = l->size;
    return list;
}
Beispiel #2
0
drmaa2_string_list drmaa2_jsession_get_job_categories(const drmaa2_jsession js) {
    if (!jsession_is_valid(js)) {
        drmaa2_lasterror_v = DRMAA2_INVALID_SESSION;
        drmaa2_lasterror_text_v = "Job session is invalid.";
        return NULL;
    }

    drmaa2_string_list jc = drmaa2_list_create(DRMAA2_STRINGLIST, (drmaa2_list_entryfree)drmaa2_string_free);
    return add_supported_job_categories(jc);
}
Beispiel #3
0
int main(int argc, char *argv[])
{
    char        cwd[100]; 
    drmaa2_string        jid1, jid2;

    printf("==== Create a job session with given session name.\n");
    drmaa2_jsession js = drmaa2_create_jsession("mysession", NULL);

    printf("==== Creating the job template.\n");
    drmaa2_jtemplate jt = drmaa2_jtemplate_create();
    jt->jobName = strdup("ht2");
    jt->remoteCommand = strdup("/bin/ls");
    if ( getcwd(cwd, DRMAA2_ATTR_BUFFER) == NULL )
    {   
        perror("Error getting current working directory");
        exit(-1);    
    }   
    jt->workingDirectory = strdup(cwd);
  
    jt->args=drmaa2_list_create(DRMAA2_STRINGLIST,DRMAA2_UNSET_CALLBACK);
    drmaa2_list_add(jt->args,"-l");
    drmaa2_list_add(jt->args,"-a");
    drmaa2_list_add(jt->args,"/tmp");

    jt->outputPath=strdup("stdout."DRMAA2_GW_JOB_ID);
    jt->errorPath =strdup("stderr."DRMAA2_GW_JOB_ID);

    drmaa2_j j1=NULL;
    drmaa2_j j2=NULL;

    printf("==== Submiting 2 jobs.\n");
    j1 = drmaa2_jsession_run_job(js, jt); 
    j2 = drmaa2_jsession_run_job(js, jt);
    jid1 = drmaa2_j_get_id(j1);
    jid2 = drmaa2_j_get_id(j2);
    printf("==== Your jobs have been submitted with id: %s and %s\n", jid1, jid2);

    drmaa2_j_list jobs = drmaa2_jsession_get_jobs(js, NULL);
    printf("==== There are %ld jobs in the job list\n", drmaa2_list_size(jobs));
  
    drmaa2_j_wait_terminated(j1, DRMAA2_INFINITE_TIME);
    drmaa2_j_wait_terminated(j2, DRMAA2_INFINITE_TIME); 

    printf("==== Destroying job template and job session.\n");
    drmaa2_list_free(&jobs);
    drmaa2_jtemplate_free(&jt);
    drmaa2_destroy_jsession("mysession");
    drmaa2_jsession_free(&js);

    printf("==== Exiting now.\n");

    return 0;
    
}
Beispiel #4
0
drmaa2_j_list drmaa2_jsession_get_jobs (const drmaa2_jsession js, const drmaa2_jinfo filter) {
    if (!jsession_is_valid(js)) {
        drmaa2_lasterror_v = DRMAA2_INVALID_SESSION;
        drmaa2_lasterror_text_v = "Job session is invalid.";
        return NULL;
    }

    drmaa2_j_list jobs = drmaa2_list_create(DRMAA2_JOBLIST, (drmaa2_list_entryfree)drmaa2_j_free);
    jobs = get_jobs(jobs, js, filter);

    return jobs;
}
Beispiel #5
0
drmaa2_r_list drmaa2_rsession_get_reservations(const drmaa2_rsession rs) {
    if (!rsession_is_valid(rs)) {
        drmaa2_lasterror_v = DRMAA2_INVALID_SESSION;
        drmaa2_lasterror_text_v = "Reservation session is invalid.";
        return NULL;
    }

    drmaa2_r_list reservations = drmaa2_list_create(DRMAA2_RESERVATIONLIST, (drmaa2_list_entryfree)drmaa2_r_free);
    reservations = get_session_reservations(reservations, rs->name);

    return reservations;
}
Beispiel #6
0
drmaa2_j_list drmaa2_msession_get_all_jobs(const drmaa2_msession ms, const drmaa2_jinfo filter) {
    drmaa2_j_list jobs = drmaa2_list_create(DRMAA2_JOBLIST, (drmaa2_list_entryfree)drmaa2_j_free);
    jobs = get_jobs(jobs, NULL, filter);
    return jobs;
}
Beispiel #7
0
drmaa2_r_list drmaa2_msession_get_all_reservations(const drmaa2_msession ms) {
    drmaa2_r_list reservations = drmaa2_list_create(DRMAA2_RESERVATIONLIST, (drmaa2_list_entryfree)drmaa2_r_free);
    reservations = get_reservations(reservations);
    return reservations;
}
Beispiel #8
0
drmaa2_jarray drmaa2_jsession_run_bulk_jobs(const drmaa2_jsession js, const drmaa2_jtemplate jt, 
    long long begin_index, long long end_index, long long step, long long max_parallel) {
    if (end_index < begin_index) {
        drmaa2_lasterror_v = DRMAA2_INVALID_ARGUMENT;
        drmaa2_lasterror_text_v = "The beginIndex value must be less than or equal to endIndex.";
        return NULL;
    } else if (begin_index < 1) {
        drmaa2_lasterror_v = DRMAA2_INVALID_ARGUMENT;
        drmaa2_lasterror_text_v = "Only positive index numbers are allowed for the beginIndex.";
        return NULL;
    }
    unsigned long index = begin_index;
    drmaa2_j j;

    drmaa2_string_list sl = drmaa2_list_create(DRMAA2_STRINGLIST, (drmaa2_list_entryfree)drmaa2_string_free);

    char *workingDirectory = jt->workingDirectory;
    char *inputPath = jt->inputPath;
    char *outputPath = jt->outputPath;
    char *errorPath = jt->errorPath;
    while (index <= end_index) {
    // Start replace placeholders
        char *index_c;
        char *tmp_working_dir;
        char *tmp_input_path;
        char *tmp_output_path;
        char *tmp_error_path;
	if (-1 == asprintf(&index_c, "%lu", index)) {
		drmaa2_lasterror_v = DRMAA2_INTERNAL;
		drmaa2_lasterror_text_v = "Error on asprintf() usage.";
		return NULL;
	}   

        tmp_working_dir = str_replace(jt->workingDirectory, "$DRMAA2_INDEX$", index_c);
        jt->workingDirectory = str_replace(tmp_working_dir, "$DRMAA2_HOME_DIR$", "~");
        drmaa2_string_free(&tmp_working_dir);

        tmp_input_path = str_replace(jt->inputPath, "$DRMAA2_INDEX$", index_c);
        jt->inputPath = str_replace(tmp_input_path, "$DRMAA2_HOME_DIR$", "~");
        drmaa2_string_free(&tmp_input_path);
        tmp_input_path = jt->inputPath;
        jt->inputPath = str_replace(tmp_input_path, "$DRMAA2_WORKING_DIR$", ".");
        drmaa2_string_free(&tmp_input_path);

        tmp_output_path = str_replace(jt->outputPath, "$DRMAA2_INDEX$", index_c);
        jt->outputPath = str_replace(tmp_output_path, "$DRMAA2_HOME_DIR$", "~");
        drmaa2_string_free(&tmp_output_path);
        tmp_output_path = jt->outputPath;
        jt->outputPath = str_replace(tmp_output_path, "$DRMAA2_WORKING_DIR$", ".");
        drmaa2_string_free(&tmp_output_path);

        tmp_error_path = str_replace(jt->errorPath, "$DRMAA2_INDEX$", index_c);
        jt->errorPath = str_replace(tmp_error_path, "$DRMAA2_HOME_DIR$", "~");
        drmaa2_string_free(&tmp_error_path);
        tmp_error_path = jt->errorPath;
        jt->errorPath = str_replace(tmp_error_path, "$DRMAA2_WORKING_DIR$", ".");
        drmaa2_string_free(&tmp_error_path);
    // End replace placeholders

        j = drmaa2_jsession_run_job(js, jt);

    // Start clean up replacement variables
        tmp_working_dir = jt->workingDirectory;
        jt->workingDirectory = workingDirectory;
        drmaa2_string_free(&tmp_working_dir);

        tmp_input_path = jt->inputPath;
        jt->inputPath = inputPath;
        drmaa2_string_free(&tmp_input_path);

        tmp_output_path = jt->outputPath;
        jt->outputPath = outputPath;
        drmaa2_string_free(&tmp_output_path);

        tmp_error_path = jt->errorPath;
        jt->errorPath = errorPath;
        drmaa2_string_free(&tmp_error_path);

        free(index_c);
    // End clean up replacement variables

        drmaa2_list_add(sl, strdup(j->id));
        drmaa2_j_free(&j);
        index += step;
    }

    long long template_id = save_jtemplate(jt, js->name);
    long long id = save_jarray(js->name, template_id, sl);
    drmaa2_list_free(&sl);
    drmaa2_jarray ja = (drmaa2_jarray)malloc(sizeof(drmaa2_jarray_s));
    char *cid;
   
    if (-1 == asprintf(&cid, "%lld", id)) {
      drmaa2_lasterror_v = DRMAA2_INTERNAL;
      drmaa2_lasterror_text_v = "Error on asprintf() usage.";
      return NULL;
    }

    ja->id = cid; //already allocated
    ja->session_name = strdup(js->name);
    return ja;
}
Beispiel #9
0
drmaa2_string_list drmaa2_get_rsession_names(void) {
    drmaa2_string_list session_names = drmaa2_list_create(DRMAA2_STRINGLIST, (drmaa2_list_entryfree)drmaa2_string_free);
    session_names = get_rsession_names(session_names);
    return session_names;
}