* The natively implemented methods connected to the MSG task *
******************************************************************/
- /**
- * The natively implemented method to create a MSG task.
- *
- * @param name The name of th task.
- * @param computeDuration A value of the processing amount (in flop) needed
- * to process the task. If 0, then it cannot be executed
- * with the execute() method. This value has to be >= 0.
- * @param messageSize A value of amount of data (in bytes) needed to transfert
- * this task. If 0, then it cannot be transfered this task.
- * If 0, then it cannot be transfered with the get() and put()
- * methods. This value has to be >= 0.
- * @param task The java task object to bind with the native task to create.
- *
- * @exception IllegalArgumentException if compute duration <0 or message size <0
- *
- * @see Task.create()
- */
- final static native void taskCreate(Task task, String name,
- double computeDuration,
- double messageSize)
- throws IllegalArgumentException;
-
/**
* The natively implemented method to get the sender of a task.
*
*/
final static native void taskCancel(Task task);
- /**
- * The natively implemented method to create a MSG parallel task.
- *
- * @param name The name of the parallel task.
- * @param hosts The list of hosts implied by the parallel task.
- * @param computeDurations The total number of operations that have to be performed
- * on the hosts.
- * @param messageSizes An array of doubles
- *
- * @see ParallelTask.create()
- */
- final static native void parallelTaskCreate(Task pTask, String name,
- Host[]hosts,
- double[]computeDurations,
- double[]messageSizes)
- throws NullPointerException, IllegalArgumentException;
-
/**
* The natively implemented method to get the computing amount of the task.
*
*/
final static native void taskSetPriority(Task task, double priority);
- /**
- * The natively implemented method to destroy a MSG task.
- *
- * @param The task to destroy.
- *
- *
- * @see Task.destroy()
- */
- final static native void taskDestroy(Task task) ;
-
/**
* The natively implemented method to execute a MSG task.
*
/** Default constructor (all fields to 0 or null) */
public Task() {
- MsgNative.taskCreate(this, null, 0, 0);
+ create(null, 0, 0);
}
+
/* * * *
* * Constructors * *
* * * */
* This value has to be >= 0.
*/
public Task(String name, double computeDuration, double messageSize) {
- MsgNative.taskCreate(this, name, computeDuration, messageSize);
+ create(name, computeDuration, messageSize);
}
/**
* Construct an new parallel task with the specified processing amount and amount for each host
* @param messageSizes A matrix describing the amount of data to exchange between hosts.
*/
public Task(String name, Host[]hosts, double[]computeDurations, double[]messageSizes) {
- MsgNative.parallelTaskCreate(this, name, hosts, computeDurations, messageSizes);
+ parallelCreate(name, hosts, computeDurations, messageSizes);
}
+
+ /**
+ * The natively implemented method to create a MSG task.
+ *
+ * @param name The name of th task.
+ * @param computeDuration A value of the processing amount (in flop) needed
+ * to process the task. If 0, then it cannot be executed
+ * with the execute() method. This value has to be >= 0.
+ * @param messageSize A value of amount of data (in bytes) needed to transfert
+ * this task. If 0, then it cannot be transfered this task.
+ * If 0, then it cannot be transfered with the get() and put()
+ * methods. This value has to be >= 0.
+ * @exception IllegalArgumentException if compute duration <0 or message size <0
+ */
+ final native void create(String name,
+ double computeDuration,
+ double messageSize)
+ throws IllegalArgumentException;
+ /**
+ * The natively implemented method to create a MSG parallel task.
+ *
+ * @param name The name of the parallel task.
+ * @param hosts The list of hosts implied by the parallel task.
+ * @param computeDurations The total number of operations that have to be performed
+ * on the hosts.
+ * @param messageSizes An array of doubles
+ *
+ */
+ final native void parallelCreate(String name,
+ Host[]hosts,
+ double[]computeDurations,
+ double[]messageSizes)
+ throws NullPointerException, IllegalArgumentException;
/* * * *
* * Getters / Setters * *
* * * */
/** Gets the name of a task
+ * FIXME: Cache it.
* @return
*/
- public String getName() {
- return MsgNative.taskGetName(this);
- }
+ public native String getName();
/** Gets the sender of the task */
Process getSender() {
return MsgNative.taskGetSender(this);
* @exception NativeException if the destruction failed.
*/
protected void finalize() throws NativeException {
- if (this.bind != 0)
- MsgNative.taskDestroy(this);
+ destroy();
}
-
+ /**
+ * The natively implemented method to destroy a MSG task.
+ */
+ protected native void destroy();
/** Send the task asynchronously on the mailbox identified by the specified name,
* with no way to retrieve whether the communication succeeded or not
* The MSG task connected functions implementation. *
***************************************************************************************/
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_MsgNative_taskCreate(JNIEnv * env, jclass cls,
- jobject jtask, jstring jname,
- jdouble jcomputeDuration,
- jdouble jmessageSize)
-{
- m_task_t task; /* the native task to create */
- const char *name = NULL; /* the name of the task */
-
- if (jcomputeDuration < 0) {
- jxbt_throw_illegal(env,
- bprintf
- ("Task ComputeDuration (%f) cannot be negative",
- (double) jcomputeDuration));
- return;
- }
-
- if (jmessageSize < 0) {
- jxbt_throw_illegal(env,
- bprintf("Task MessageSize (%f) cannot be negative",
- (double) jmessageSize));
- return;
- }
-
- if (jname) {
- /* get the C string from the java string */
- name = (*env)->GetStringUTFChars(env, jname, 0);
- }
-
-
- /* create the task */
- task =
- MSG_task_create(name, (double) jcomputeDuration,
- (double) jmessageSize, NULL);
- if (jname)
- (*env)->ReleaseStringUTFChars(env, jname, name);
-
- /* bind & store the task */
- jtask_bind(jtask, task, env);
- MSG_task_set_data(task, jtask);
-}
-
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_MsgNative_parallel_taskCreate(JNIEnv * env, jclass cls,
- jobject jtask,
- jstring jname,
- jobjectArray jhosts,
- jdoubleArray
- jcomputeDurations_arg,
- jdoubleArray
- jmessageSizes_arg)
-{
-
- m_task_t task; /* the native parallel task to create */
- const char *name; /* the name of the task */
- int host_count;
- m_host_t *hosts;
- double *computeDurations;
- double *messageSizes;
- jdouble *jcomputeDurations;
- jdouble *jmessageSizes;
-
- jobject jhost;
- int index;
-
-
- if (!jcomputeDurations_arg) {
- jxbt_throw_null(env,
- xbt_strdup
- ("Parallel task compute durations cannot be null"));
- return;
- }
-
- if (!jmessageSizes_arg) {
- jxbt_throw_null(env,
- xbt_strdup
- ("Parallel task message sizes cannot be null"));
- return;
- }
-
- if (!jname) {
- jxbt_throw_null(env, xbt_strdup("Parallel task name cannot be null"));
- return;
- }
-
- host_count = (int) (*env)->GetArrayLength(env, jhosts);
-
-
- hosts = xbt_new0(m_host_t, host_count);
- computeDurations = xbt_new0(double, host_count);
- messageSizes = xbt_new0(double, host_count * host_count);
-
- jcomputeDurations =
- (*env)->GetDoubleArrayElements(env, jcomputeDurations_arg, 0);
- jmessageSizes =
- (*env)->GetDoubleArrayElements(env, jmessageSizes_arg, 0);
-
- for (index = 0; index < host_count; index++) {
- jhost = (*env)->GetObjectArrayElement(env, jhosts, index);
- hosts[index] = jhost_get_native(env, jhost);
- computeDurations[index] = jcomputeDurations[index];
- }
- for (index = 0; index < host_count * host_count; index++) {
- messageSizes[index] = jmessageSizes[index];
- }
-
- (*env)->ReleaseDoubleArrayElements(env, jcomputeDurations_arg,
- jcomputeDurations, 0);
- (*env)->ReleaseDoubleArrayElements(env, jmessageSizes_arg, jmessageSizes,
- 0);
-
-
- /* get the C string from the java string */
- name = (*env)->GetStringUTFChars(env, jname, 0);
-
- task =
- MSG_parallel_task_create(name, host_count, hosts, computeDurations,
- messageSizes, NULL);
-
- (*env)->ReleaseStringUTFChars(env, jname, name);
-
- /* associate the java task object and the native task */
- jtask_bind(jtask, task, env);
-
- MSG_task_set_data(task, (void *) jtask);
-
- if (!MSG_task_get_data(task))
- jxbt_throw_jni(env, "global ref allocation failed");
-}
-
JNIEXPORT jobject JNICALL
Java_org_simgrid_msg_MsgNative_taskGetSender(JNIEnv * env, jclass cls,
jobject jtask)
MSG_task_set_priority(task, (double) priority);
}
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_MsgNative_taskDestroy(JNIEnv * env, jclass cls,
- jobject jtask_arg)
-{
- /* get the native task */
- m_task_t task = jtask_to_native_task(jtask_arg, env);
-
- if (!task) {
- jxbt_throw_notbound(env, "task", task);
- return;
- }
- MSG_error_t rv = MSG_task_destroy(task);
-
- jxbt_check_res("MSG_task_destroy()", rv, MSG_OK,
- bprintf("unexpected error , please report this bug"));
-}
-
JNIEXPORT void JNICALL
Java_org_simgrid_msg_MsgNative_taskExecute(JNIEnv * env, jclass cls,
jobject jtask)
JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_MsgNative_hostIsAvail
(JNIEnv *, jclass, jobject);
-/*
- * Class simgrid_msg_Msg
- * Method taskCreate
- * Signature (Lsimgrid/msg/Task;Ljava/lang/String;DD)V
- */
-JNIEXPORT void JNICALL Java_org_simgrid_msg_MsgNative_taskCreate
- (JNIEnv *, jclass, jobject, jstring, jdouble, jdouble);
-
-JNIEXPORT void JNICALL
-Java_org_simgrid_msg_MsgNative_parallel_taskCreate(JNIEnv *, jclass, jobject,
- jstring, jobjectArray,
- jdoubleArray, jdoubleArray);
-
/*
* Class simgrid_msg_Msg
* Method taskGetSender
JNIEXPORT void JNICALL Java_org_simgrid_msg_MsgNative_taskSetPriority
(JNIEnv *, jclass, jobject, jdouble);
-/*
- * Class simgrid_msg_Msg
- * Method taskDestroy
- * Signature (Lsimgrid/msg/Task;)V
- */
-JNIEXPORT void JNICALL Java_org_simgrid_msg_MsgNative_taskDestroy
- (JNIEnv *, jclass, jobject);
-
/*
* Class simgrid_msg_Msg
* Method taskExecute
m_task_t *task_received;
task_received = (m_task_t*) (long) (*env)->GetLongField(env, jcomm, jcomm_field_Comm_taskBind);
- if (task_received != NULL) {
- xbt_free(task_received);
- }
+ xbt_free(task_received);
comm = (msg_comm_t) (long) (*env)->GetLongField(env, jcomm, jcomm_field_Comm_bind);
MSG_comm_destroy(comm);
#include "jmsg.h"
#include "jmsg_task.h"
#include "jxbt_utilities.h"
+#include "jmsg_host.h"
#include <msg/msg.h>
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
jtask_field_Comm_receiving = jxbt_get_sfield(env, "org/simgrid/msg/Comm", "receiving", "Z");
}
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Task_create(JNIEnv * env,
+ jobject jtask, jstring jname,
+ jdouble jcomputeDuration,
+ jdouble jmessageSize)
+{
+ m_task_t task; /* the native task to create */
+ const char *name = NULL; /* the name of the task */
+
+ if (jcomputeDuration < 0) {
+ jxbt_throw_illegal(env,
+ bprintf
+ ("Task ComputeDuration (%f) cannot be negative",
+ (double) jcomputeDuration));
+ return;
+ }
+
+ if (jmessageSize < 0) {
+ jxbt_throw_illegal(env,
+ bprintf("Task MessageSize (%f) cannot be negative",
+ (double) jmessageSize));
+ return;
+ }
+
+ if (jname) {
+ /* get the C string from the java string */
+ name = (*env)->GetStringUTFChars(env, jname, 0);
+ }
+
+
+ /* create the task */
+ task =
+ MSG_task_create(name, (double) jcomputeDuration,
+ (double) jmessageSize, NULL);
+ if (jname)
+ (*env)->ReleaseStringUTFChars(env, jname, name);
+
+ /* bind & store the task */
+ jtask_bind(jtask, task, env);
+ MSG_task_set_data(task, jtask);
+}
+
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Task_parallelCreate(JNIEnv * env,
+ jobject jtask,
+ jstring jname,
+ jobjectArray jhosts,
+ jdoubleArray
+ jcomputeDurations_arg,
+ jdoubleArray
+ jmessageSizes_arg) {
+
+ m_task_t task; /* the native parallel task to create */
+ const char *name; /* the name of the task */
+ int host_count;
+ m_host_t *hosts;
+ double *computeDurations;
+ double *messageSizes;
+ jdouble *jcomputeDurations;
+ jdouble *jmessageSizes;
+
+ jobject jhost;
+ int index;
+
+
+ if (!jcomputeDurations_arg) {
+ jxbt_throw_null(env,
+ xbt_strdup
+ ("Parallel task compute durations cannot be null"));
+ return;
+ }
+
+ if (!jmessageSizes_arg) {
+ jxbt_throw_null(env,
+ xbt_strdup
+ ("Parallel task message sizes cannot be null"));
+ return;
+ }
+
+ if (!jname) {
+ jxbt_throw_null(env, xbt_strdup("Parallel task name cannot be null"));
+ return;
+ }
+
+ host_count = (int) (*env)->GetArrayLength(env, jhosts);
+
+
+ hosts = xbt_new0(m_host_t, host_count);
+ computeDurations = xbt_new0(double, host_count);
+ messageSizes = xbt_new0(double, host_count * host_count);
+
+ jcomputeDurations =
+ (*env)->GetDoubleArrayElements(env, jcomputeDurations_arg, 0);
+ jmessageSizes =
+ (*env)->GetDoubleArrayElements(env, jmessageSizes_arg, 0);
+
+ for (index = 0; index < host_count; index++) {
+ jhost = (*env)->GetObjectArrayElement(env, jhosts, index);
+ hosts[index] = jhost_get_native(env, jhost);
+ computeDurations[index] = jcomputeDurations[index];
+ }
+ for (index = 0; index < host_count * host_count; index++) {
+ messageSizes[index] = jmessageSizes[index];
+ }
+
+ (*env)->ReleaseDoubleArrayElements(env, jcomputeDurations_arg,
+ jcomputeDurations, 0);
+ (*env)->ReleaseDoubleArrayElements(env, jmessageSizes_arg, jmessageSizes,
+ 0);
+
+
+ /* get the C string from the java string */
+ name = (*env)->GetStringUTFChars(env, jname, 0);
+
+ task =
+ MSG_parallel_task_create(name, host_count, hosts, computeDurations,
+ messageSizes, NULL);
+
+ (*env)->ReleaseStringUTFChars(env, jname, name);
+
+ /* associate the java task object and the native task */
+ jtask_bind(jtask, task, env);
+
+ MSG_task_set_data(task, (void *) jtask);
+
+ if (!MSG_task_get_data(task))
+ jxbt_throw_jni(env, "global ref allocation failed");
+}
+
+JNIEXPORT jstring JNICALL
+Java_org_simgrid_msg_Task_getName(JNIEnv * env,
+ jobject jtask) {
+ m_task_t task = jtask_to_native_task(jtask, env);
+
+ if (!task) {
+ jxbt_throw_notbound(env, "task", jtask);
+ return NULL;
+ }
+
+ return (*env)->NewStringUTF(env, MSG_task_get_name(task));
+}
+
JNIEXPORT jobject JNICALL
Java_org_simgrid_msg_Task_irecv(JNIEnv * env, jclass cls, jstring jmailbox) {
msg_comm_t comm;
* Otherwise the function returns false.
*/
jboolean jtask_is_valid(jobject jtask, JNIEnv * env);
+/*
+ * Class org_simgrid_msg_Task
+ * Method create
+ */
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Task_create
+ (JNIEnv * env, jobject jtask, jstring jname, jdouble jcomputeDuration, jdouble jmessageSize);
+/*
+ * Class org_simgrid_msg_Task
+ * Method parallelCreate
+ */
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Task_parallelCreate
+ (JNIEnv *, jobject,
+ jstring, jobjectArray,
+ jdoubleArray,
+ jdoubleArray);
+/*
+ * Class org_simgrid_msg_Task
+ * Method destroy
+ * Signature (Lsimgrid/msg/Task;)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_destroy
+ (JNIEnv *, jobject);
+/*
+ * Class org_simgrid_msg_Task
+ * Method getName
+ * Signature ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_org_simgrid_msg_Task_getName
+ (JNIEnv *, jobject);
+/*
+ * Class org_simgrid_msg_Task
+ * Method nativeInit
+ * Signature ();
+ */
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Task_nativeInit(JNIEnv *env, jclass cls);
-
+/**
+ * Class org_simgrid_msg_Task
+ * Method irecv
+ * Signature (Ljava/lang/String;)Lorg/simgrid/msg/Comm;
+ */
JNIEXPORT jobject JNICALL
Java_org_simgrid_msg_Task_irecv(JNIEnv * env, jclass cls, jstring jmailbox);
-
+/**
+ * Class org_simgrid_msg_Task
+ * Method isend
+ * Signature (Lorg/simgrid/msg/Task;Ljava/lang/String;)Lorg/simgrid/msg/Comm;
+ */
JNIEXPORT jobject JNICALL
Java_org_simgrid_msg_Task_isend(JNIEnv *env, jobject jtask, jstring jmailbox);