From 6596e7b25f569de5c4b1dc1a0816c5210c82c9ca Mon Sep 17 00:00:00 2001 From: Bryan J Lunt Date: Tue, 4 Jun 2013 03:27:47 -0500 Subject: [PATCH] Basic Implementation... Probably Broken in some way. --- Makefile | 17 +++++------ constants.h | 25 ++++++++++++++++ drmaa_impl_stolen.h | 62 --------------------------------------- jdrmaa.h | 70 +++++++++++++++++++++++++++++++++++++++------ jdrmaa.i | 70 ++------------------------------------------- lib/.gitignore | 0 test/Test.java | 14 +++++---- 7 files changed, 106 insertions(+), 152 deletions(-) create mode 100644 constants.h delete mode 100644 drmaa_impl_stolen.h create mode 100644 lib/.gitignore diff --git a/Makefile b/Makefile index 2ea4b88..c5dafd7 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,23 @@ - +CPP=g++ CC=gcc + CFLAGS=$(shell pbs-config --cflags) -I/usr/lib/jvm/java-1.7.0-openjdk.x86_64/include/ -I/usr/lib/jvm/java-1.7.0-openjdk.x86_64/include/linux -LIBS=$(shell pbs-config --libs) -ldrmaa +LIBS=$(shell pbs-config --libs) -ldrmaa -lstdc++ LIBNAME=lib/libjdrmaa.so all: clean lib javac -javac: jdrmaa_wrap.c +javac: jdrmaa_wrap.cxx javac jdrmaa/*.java javac test/*.java -lib: jdrmaa_wrap.c jdrmaa.i - $(CC) $(CFLAGS) $(LIBS) -fPIC -c jdrmaa_wrap.c +lib: jdrmaa_wrap.cxx jdrmaa.i + $(CPP) $(CFLAGS) $(LIBS) -fPIC -c jdrmaa_wrap.cxx $(CC) $(LIBS) -shared jdrmaa_wrap.o -o $(LIBNAME) -jdrmaa_wrap.c: jdrmaa.i - swig -java -package jdrmaa -outdir jdrmaa $(CFLAGS) jdrmaa.i +jdrmaa_wrap.cxx: jdrmaa.i + swig -c++ -java -package jdrmaa -outdir jdrmaa $(CFLAGS) jdrmaa.i clean: - rm -f jdrmaa_wrap.c jdrmaa_wrap.o $(LIBNAME) jdrmaa/* test/*.class + rm -f jdrmaa_wrap.* $(LIBNAME) jdrmaa/* test/*.class diff --git a/constants.h b/constants.h new file mode 100644 index 0000000..6e3327c --- /dev/null +++ b/constants.h @@ -0,0 +1,25 @@ +#ifndef STOLEN_CONSTS +#define STOLEN_CONSTS + +#define DRMAA_TIMEOUT_NO_WAIT 0 +#define DRMAA_TIMEOUT_WAIT_FOREVER -1 +#define DRMAA_PS_UNDETERMINED 0x00 +#define DRMAA_PS_QUEUED_ACTIVE 0x10 +#define DRMAA_PS_SYSTEM_ON_HOLD 0x11 +#define DRMAA_PS_USER_ON_HOLD 0x12 +#define DRMAA_PS_USER_SYSTEM_ON_HOLD 0x13 +#define DRMAA_PS_RUNNING 0x20 +#define DRMAA_PS_SYSTEM_SUSPENDED 0x21 +#define DRMAA_PS_USER_SUSPENDED 0x22 +#define DRMAA_PS_USER_SYSTEM_SUSPENDED 0x23 +#define DRMAA_PS_DONE 0x30 +#define DRMAA_PS_FAILED 0x40 +#define DRMAA_CONTROL_SUSPEND 0 +#define DRMAA_CONTROL_RESUME 1 +#define DRMAA_CONTROL_HOLD 2 +#define DRMAA_CONTROL_RELEASE 3 +#define DRMAA_CONTROL_TERMINATE 4 +#define DRMAA_JOB_IDS_SESSION_ALL "DRMAA_JOB_IDS_SESSION_ALL" +#define DRMAA_JOB_IDS_SESSION_ANY "DRMAA_JOB_IDS_SESSION_ANY" + +#endif diff --git a/drmaa_impl_stolen.h b/drmaa_impl_stolen.h deleted file mode 100644 index 61a2ab6..0000000 --- a/drmaa_impl_stolen.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef DRMAA_STOLEN -#define DRMAA_STOLEN - -/* - * This file contains fragments taken from : https://github.com/adaptivecomputing/torque/blob/master/src/drmaa/src/drmaa_impl.h - * - * Those fragments are covered under the GPL, so I must include the GPL statement here. - */ - -/* $Id: drmaa_impl.h,v 1.9 2006/09/08 18:18:08 ciesnik Exp $ */ -/* - * * DRMAA library for Torque/PBS - * * Copyright (C) 2006 Poznan Supercomputing and Networking Center - * * DSP team - * * - * * This library is free software; you can redistribute it and/or - * * modify it under the terms of the GNU Lesser General Public - * * License as published by the Free Software Foundation; either - * * version 2.1 of the License, or (at your option) any later version. - * * - * * This library is distributed in the hope that it will be useful, - * * but WITHOUT ANY WARRANTY; without even the implied warranty of - * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * * Lesser General Public License for more details. - * * - * * You should have received a copy of the GNU Lesser General Public - * * License along with this library; if not, write to the Free Software - * * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ - - - -#include - -typedef struct drmaa_session_s drmaa_session_t; - -typedef struct drmaa_job_s drmaa_job_t; - -/** DRMAA session data. */ - -struct drmaa_session_s - { - }; - -struct drmaa_job_template_s - { - }; - - -struct drmaa_attr_names_s - { - }; - -struct drmaa_attr_values_s - { - }; - -struct drmaa_job_ids_s - { - }; - -#endif diff --git a/jdrmaa.h b/jdrmaa.h index 773d3a7..f1044f1 100644 --- a/jdrmaa.h +++ b/jdrmaa.h @@ -1,8 +1,63 @@ #include + +class DRMAA{ +public: + static char *get_contact(){ + char *contact = (char*)malloc(1024*sizeof(char)); + drmaa_get_contact(contact,1024,NULL,0); + return contact;//I bet this memory leaks. + } + + static int init(){ + return drmaa_init(NULL,NULL,0); + } + + static int init(const char *contact){ + return drmaa_init(contact,NULL,0); + } + + static int exit(){ + return drmaa_exit(NULL,0); + } + + static void control(const char *job_id, int action){ + drmaa_control(job_id,action,NULL,0); + } + + static int job_ps(const char *job_id){ + int retval; + drmaa_job_ps(job_id, &retval,NULL,0); + return retval; + } + + static int synchronize(const char *job_ids[], signed long timeout, int dispose){ + return drmaa_synchronize(job_ids,timeout,dispose,NULL,0); + } + + //static int wait(const char *job_id +}; + +#define JOB_ID_SIZE 256 +class Job{ + public: + char *id; + + Job(){ + id = (char*)malloc(JOB_ID_SIZE*sizeof(char)); + } + + ~Job(){ + free(id); + } + +}; + class JobTemplate{ + private: drmaa_job_template_t *jt; - + + public: JobTemplate(){ drmaa_allocate_job_template(&jt,NULL,0); } @@ -18,13 +73,13 @@ class JobTemplate{ char *get_attribute(const char *name){ int reason; char *retval; - retval = malloc(1024*sizeof(char)); + retval = (char*)malloc(1024*sizeof(char)); reason = drmaa_get_attribute(jt,name,retval,1024,NULL,0); return retval; } int set_vector_attribute(const char *name, const char *value[]){ - return drmaa_set_vector_attribute($self,name,value,NULL,0); + return drmaa_set_vector_attribute(jt,name,value,NULL,0); } /* @@ -35,13 +90,10 @@ class JobTemplate{ * } * */ - char *start(){ + Job* start(){ int reason; - char *retval; - retval = malloc(256*sizeof(char)); - reason = drmaa_run_job(retval, 256, $self, NULL, 0); + Job *retval = new Job(); + reason = drmaa_run_job(retval->id, JOB_ID_SIZE, jt, NULL, 0); return retval; } - - }; diff --git a/jdrmaa.i b/jdrmaa.i index 9a43203..0e0397e 100644 --- a/jdrmaa.i +++ b/jdrmaa.i @@ -1,72 +1,8 @@ %module jdrmaa %include "typemaps.i" %{ -#include "drmaa_impl_stolen.h" -#include +#include "jdrmaa.h" %} - - -%ignore drmaa_allocate_job_template; -%ignore drmaa_delete_job_template; -%ignore drmaa_set_attribute; -%ignore drmaa_get_attribute; -%ignore drmaa_set_vector_attribute; -%ignore drmaa_get_vector_attribute; -%ignore drmaa_run_job; - -%include "drmaa_impl_stolen.h" -%include - -%extend drmaa_job_template_s { - drmaa_job_template_s(){ - drmaa_job_template_t *jt; - drmaa_allocate_job_template(&jt,NULL,0); - return jt; - } - - ~drmma_job_template_s(){ - drmaa_delete_job_template($self,NULL,0); - } - - int set_attribute(const char *name, const char *value){ - return drmaa_set_attribute($self, name, value, NULL, 0); - } - - - char *get_attribute(const char *name){ - int reason; - char *retval; - retval = malloc(1024*sizeof(char)); - reason = drmaa_get_attribute($self,name,retval,1024,NULL,0); - return retval; - } - - int set_vector_attribute(const char *name, const char *value[]){ - return drmaa_set_vector_attribute($self,name,value,NULL,0); - } - - drmaa_attr_values_t *get_vector_attribute(const char *name){ - drmaa_attr_values_t *values; - drmaa_get_vector_attribute($self,name,&values,NULL,0); - return values; - } - - char *start(){ - int reason; - char *retval; - retval = malloc(256*sizeof(char)); - reason = drmaa_run_job(retval, 256, $self, NULL, 0); - return retval; - } -}; - -drmaa_attr_names_t foo_get_attribute_names(){ - int reason; - drmaa_attr_names_t *retval; - reason = drmaa_get_attribute_names(&retval,NULL,0); - return retval; -} - -%extend drmaa_attr_names_s { -} +%include "jdrmaa.h" +%include "constants.h" diff --git a/lib/.gitignore b/lib/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/test/Test.java b/test/Test.java index a5407b5..0c094e4 100644 --- a/test/Test.java +++ b/test/Test.java @@ -5,14 +5,16 @@ public class Test { public static void main(String argv[]) { System.loadLibrary("jdrmaa"); - jdrmaa.drmaa_init(null,null,0); + DRMAA.init(); - drmaa_job_template_s myTemplate = new drmaa_job_template_s(); - myTemplate.set_attribute("drmaa_remote_command","/tmp/test.sh"); - myTemplate.set_attribute("drmaa_job_name","Job Submit from DRMAA"); - System.out.println(myTemplate.get_attribute("drmaa_job_name")); - System.out.println(myTemplate.start()); + JobTemplate jt = new JobTemplate(); + jt.set_attribute("drmaa_remote_command","/tmp/test.sh"); + jt.set_attribute("drmaa_job_name","Job Submit from DRMAA"); + System.out.println(jt.get_attribute("drmaa_job_name")); + Job newJob = jt.start(); + System.out.println(newJob.getId()); + DRMAA.exit(); //System.out.println(example.getMy_variable()); //System.out.println(example.fact(5)); //System.out.println(example.get_time());