/* Functions related to the java task instances. */
-/* Copyright (c) 2007, 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2007, 2009-2010, 2013-2014. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
+ * under the terms of the license (GNU LGPL) which comes with this package. */
#include "jmsg.h"
#include "jxbt_utilities.h"
-#include <msg/msg.h>
+#include <simgrid/msg.h>
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Task_create(JNIEnv * env,
jobject jtask, jstring jname,
- jdouble jcomputeDuration,
- jdouble jmessageSize)
+ jdouble jflopsAmount,
+ jdouble jbytesAmount)
{
msg_task_t task; /* the native task to create */
const char *name = NULL; /* the name of the task */
- if (jcomputeDuration < 0) {
+ if (jflopsAmount < 0) {
jxbt_throw_illegal(env,
bprintf
- ("Task ComputeDuration (%f) cannot be negative",
- (double) jcomputeDuration));
+ ("Task flopsAmount (%f) cannot be negative",
+ (double) jflopsAmount));
return;
}
- if (jmessageSize < 0) {
+ if (jbytesAmount < 0) {
jxbt_throw_illegal(env,
- bprintf("Task MessageSize (%f) cannot be negative",
- (double) jmessageSize));
+ bprintf("Task bytesAmount (%f) cannot be negative",
+ (double) jbytesAmount));
return;
}
/* create the task */
task =
- MSG_task_create(name, (double) jcomputeDuration,
- (double) jmessageSize, NULL);
+ MSG_task_create(name, (double) jflopsAmount,
+ (double) jbytesAmount, NULL);
if (jname)
(*env)->ReleaseStringUTFChars(env, jname, name);
/* sets the task name */
if (!jcomputeDurations_arg) {
jxbt_throw_null(env,
xbt_strdup
- ("Parallel task compute durations cannot be null"));
+ ("Parallel task flops amounts cannot be null"));
return;
}
if (!jmessageSizes_arg) {
jxbt_throw_null(env,
xbt_strdup
- ("Parallel task message sizes cannot be null"));
+ ("Parallel task bytes amounts cannot be null"));
return;
}
}
}
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Task_setBound(JNIEnv * env, jobject jtask, jdouble load)
+{
+ msg_task_t task = jtask_to_native_task(jtask, env);
+
+ if (!task) {
+ jxbt_throw_notbound(env, "task", jtask);
+ return;
+ }
+ MSG_task_set_bound(task, load);
+}
+
JNIEXPORT jstring JNICALL
Java_org_simgrid_msg_Task_getName(JNIEnv * env,
jobject jtask) {
if (host == NULL) {
return NULL;
}
- if (!MSG_host_get_data(host)) {
+ if (!xbt_lib_get_level(host, JAVA_HOST_LEVEL)) {
jxbt_throw_jni(env, "MSG_task_get_source() failed");
return NULL;
}
- return (jobject) MSG_host_get_data(host);
+ return (jobject) xbt_lib_get_level(host, JAVA_HOST_LEVEL);
}
JNIEXPORT jdouble JNICALL
-Java_org_simgrid_msg_Task_getComputeDuration(JNIEnv * env,
- jobject jtask)
+Java_org_simgrid_msg_Task_getFlopsAmount(JNIEnv * env, jobject jtask)
{
msg_task_t ptask = jtask_to_native_task(jtask, env);
jxbt_throw_notbound(env, "task", jtask);
return -1;
}
- return (jdouble) MSG_task_get_compute_duration(ptask);
+ return (jdouble) MSG_task_get_flops_amount(ptask);
}
-JNIEXPORT jdouble JNICALL
-Java_org_simgrid_msg_Task_getRemainingDuration(JNIEnv * env, jobject jtask)
-{
- msg_task_t ptask = jtask_to_native_task(jtask, env);
-
- if (!ptask) {
- jxbt_throw_notbound(env, "task", jtask);
- return -1;
- }
- return (jdouble) MSG_task_get_remaining_computation(ptask);
-}
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Task_setName(JNIEnv *env, jobject jtask, jobject jname) {
msg_task_t task = jtask_to_native_task(jtask, env);
MSG_task_set_priority(task, (double) priority);
}
JNIEXPORT void JNICALL
-Java_org_simgrid_msg_Task_setComputeDuration
+Java_org_simgrid_msg_Task_setFlopsAmount
(JNIEnv *env, jobject jtask, jdouble computationAmount) {
msg_task_t task = jtask_to_native_task(jtask, env);
jxbt_throw_notbound(env, "task", jtask);
return;
}
- MSG_task_set_compute_duration(task, (double) computationAmount);
+ MSG_task_set_flops_amount(task, (double) computationAmount);
}
JNIEXPORT void JNICALL
-Java_org_simgrid_msg_Task_setDataSize
+Java_org_simgrid_msg_Task_setBytesAmount
(JNIEnv *env, jobject jtask, jdouble dataSize) {
msg_task_t task = jtask_to_native_task(jtask, env);
return;
}
(*env)->SetDoubleField(env, jtask, jtask_field_Task_messageSize, dataSize);
- MSG_task_set_data_size(task, (double) dataSize);
+ MSG_task_set_bytes_amount(task, (double) dataSize);
}
JNIEXPORT void JNICALL
return jcomm;
}
+
+JNIEXPORT jobject JNICALL
+Java_org_simgrid_msg_Task_receiveBounded(JNIEnv * env, jclass cls,
+ jstring jalias, jdouble jtimeout,
+ jobject jhost, jdouble rate)
+{
+ msg_error_t rv;
+ msg_task_t *task = xbt_new(msg_task_t,1);
+ *task = NULL;
+
+ msg_host_t host = NULL;
+ jobject jtask_global, jtask_local;
+ const char *alias;
+
+ if (jhost) {
+ host = jhost_get_native(env, jhost);
+
+ if (!host) {
+ jxbt_throw_notbound(env, "host", jhost);
+ return NULL;
+ }
+ }
+
+ alias = (*env)->GetStringUTFChars(env, jalias, 0);
+ rv = MSG_task_receive_ext_bounded(task, alias, (double) jtimeout, host, (double) rate);
+ if ((*env)->ExceptionOccurred(env))
+ return NULL;
+ if (rv != MSG_OK) {
+ jmsg_throw_status(env,rv);
+ return NULL;
+ }
+ jtask_global = MSG_task_get_data(*task);
+
+ /* Convert the global ref into a local ref so that the JVM can free the stuff */
+ jtask_local = (*env)->NewLocalRef(env, jtask_global);
+ (*env)->DeleteGlobalRef(env, jtask_global);
+ MSG_task_set_data(*task, NULL);
+
+ (*env)->ReleaseStringUTFChars(env, jalias, alias);
+
+ xbt_free(task);
+
+ return (jobject) jtask_local;
+}
+
+
+JNIEXPORT jobject JNICALL
+Java_org_simgrid_msg_Task_irecvBounded(JNIEnv * env, jclass cls,
+ jstring jmailbox, jdouble rate) {
+ msg_comm_t comm;
+ const char *mailbox;
+ jclass comm_class;
+ //pointer to store the task object pointer.
+ msg_task_t *task = xbt_new(msg_task_t,1);
+ *task = NULL;
+ /* There should be a cache here */
+ comm_class = (*env)->FindClass(env, "org/simgrid/msg/Comm");
+
+ if (!comm_class) {
+ jxbt_throw_native(env,bprintf("fieldID or methodID or class not found."));
+ return NULL;
+ }
+
+ jobject jcomm = (*env)->NewObject(env, comm_class, jtask_method_Comm_constructor);
+ if (!jcomm) {
+ jxbt_throw_native(env,bprintf("Can't create a Comm object."));
+ return NULL;
+ }
+
+ mailbox = (*env)->GetStringUTFChars(env, jmailbox, 0);
+
+ comm = MSG_task_irecv_bounded(task,mailbox, (double) rate);
+
+ (*env)->SetLongField(env, jcomm, jtask_field_Comm_bind, (jlong) (long)(comm));
+ (*env)->SetLongField(env, jcomm, jtask_field_Comm_taskBind, (jlong) (long)(task));
+ (*env)->SetBooleanField(env, jcomm, jtask_field_Comm_receiving, JNI_TRUE);
+
+ (*env)->ReleaseStringUTFChars(env, jmailbox, mailbox);
+
+ return jcomm;
+}
+
JNIEXPORT jobject JNICALL
Java_org_simgrid_msg_Task_isend(JNIEnv *env, jobject jtask, jstring jmailbox) {
jclass comm_class;