X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e0188e2a2598ce57a4d21a3d7eb5f303aecaf0dd..68422deb1639b1ce574393779ae259579be53fb5:/src/bindings/java/org/simgrid/msg/Task.java diff --git a/src/bindings/java/org/simgrid/msg/Task.java b/src/bindings/java/org/simgrid/msg/Task.java index 1b2e0cdac1..0dec155c5b 100644 --- a/src/bindings/java/org/simgrid/msg/Task.java +++ b/src/bindings/java/org/simgrid/msg/Task.java @@ -1,11 +1,7 @@ -/* - * Copyright 2006-2012 The SimGrid Team. - * All right 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. - */ +/* Copyright (c) 2006-2016. 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. */ package org.simgrid.msg; @@ -28,114 +24,120 @@ public class Task { private double messageSize; - static private Long idCpt = 0L; - - private Long id; - /** Default constructor (all fields to 0 or null) */ public Task() { create(null, 0, 0); this.messageSize = 0; - setId(idCpt); - idCpt++; } /* * * * * * Constructors * * * * * */ /** - * Construct an new task with the specified processing amount and amount + * Construct a new task with the specified processing amount and amount * of data needed. * * @param name Task's name * - * @param computeDuration A value of the processing amount (in flop) needed to process the task. + * @param flopsAmount 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. + * This value has to be ≥ 0. * - * @param messageSize A value of amount of data (in bytes) needed to transfert this task. + * @param bytesAmount A value of amount of data (in bytes) needed to transfert this task. * If 0, then it cannot be transfered with the get() and put() methods. - * This value has to be >= 0. + * This value has to be ≥ 0. */ - public Task(String name, double computeDuration, double messageSize) { - create(name, computeDuration, messageSize); - this.messageSize = messageSize; - setId(idCpt); - idCpt++; + public Task(String name, double flopsAmount, double bytesAmount) { + if (flopsAmount<0) + throw new IllegalArgumentException("Task flopsAmount (" + flopsAmount + ") cannot be negative"); + if (bytesAmount<0) + throw new IllegalArgumentException("Task bytesAmount (" + bytesAmount + ") cannot be negative"); + + create(name, flopsAmount, bytesAmount); + + this.name = name; + this.messageSize = bytesAmount; } /** - * Construct an new parallel task with the specified processing amount and amount for each host + * Construct a new parallel task with the specified processing amount and amount for each host * implied. * * @param name The name of the parallel task. * @param hosts The list of hosts implied by the parallel task. - * @param computeDurations The amount of operations to be performed by each host of \a hosts. - * @param messageSizes A matrix describing the amount of data to exchange between hosts. + * @param flopsAmount The amount of operations to be performed by each host of hosts. + * flopsAmount[i] is the total number of operations that have to be + * performed on hosts[i]. + * @param bytesAmount A matrix describing the amount of data to exchange between hosts. The + * length of this array must be hosts.length * hosts.length. It is actually + * used as a matrix with the lines being the source and the columns being + * the destination of the communications. */ - public Task(String name, Host[]hosts, double[]computeDurations, double[]messageSizes) { - parallelCreate(name, hosts, computeDurations, messageSizes); + public Task(String name, Host[]hosts, double[]flopsAmount, double[]bytesAmount) { + if (flopsAmount == null) + throw new NullPointerException("Parallel task flops amounts is null"); + if (bytesAmount == null) + throw new NullPointerException("Parallel task bytes amounts is null"); + if (hosts == null) + throw new NullPointerException("Host list is null"); + if (name == null) + throw new NullPointerException("Parallel task name is null"); + + parallelCreate(name, hosts, flopsAmount, bytesAmount); + this.name = name; } - + /** * 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 + * @param name The name of the task. + * @param flopsAmount 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 + * @param bytesAmount 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 */ private final native void create(String name, - double computeDuration, - double messageSize) - throws IllegalArgumentException; + double flopsAmount, + double bytesAmount); /** * 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 + * @param hosts The list of hosts implied by the parallel task. + * @param flopsAmount The total number of operations that have to be performed * on the hosts. - * @param messageSizes An array of doubles + * @param bytesAmount An array of doubles * */ private final native void parallelCreate(String name, Host[]hosts, - double[]computeDurations, - double[]messageSizes) - throws NullPointerException, IllegalArgumentException; + double[]flopsAmount, + double[]bytesAmount); /* * * * * * Getters / Setters * * * * * */ - /** - * Gets the name of a task - */ + /** Gets the name of the task */ public String getName() { return name; } - /** - * Gets the sender of the task - * Returns null if the task hasn't been sent yet - */ + + /** Gets the sender of the task (or null if not sent yet) */ public native Process getSender(); - /** Gets the source of the task. - * Returns null if the task hasn't been sent yet. - */ + + /** Gets the source of the task (or null if not sent yet). */ public native Host getSource(); - /** Gets the computing amount of the task - * FIXME: Cache it ! - */ - public native double getComputeDuration(); - /** Gets the remaining computation of the task - */ - public native double getRemainingDuration(); + + /** Gets the remaining amount of flops to execute in this task + * + * If it's ongoing, you get the exact amount at the present time. If it's already done, it's 0. + */ + public native double getFlopsAmount(); /** * Sets the name of the task - * @param name the new task name.c + * @param name the new task name */ public native void setName(String name); /** @@ -147,65 +149,66 @@ public class Task { * @param priority The new priority of the task. */ public native void setPriority(double priority); - /** - * Set the computation amount needed to process the task - * @param computationAmount the amount of computation needed to process the task + + /** Set the computation amount needed to process the task + * + * Warning if the execution is already started and ongoing, this call does nothing. + * @param flopsAmount the amount of computation needed to process the task */ - public native void setComputeDuration(double computationAmount); + public native void setFlopsAmount(double flopsAmount); /** - * Set the data size of the task - * @param dataSize the size of the task + * Set the amount of bytes to exchange the task + * + * Warning if the communication is already started and ongoing, this call does nothing. + * @param bytesAmount the size of the task */ - public native void setDataSize(double dataSize); + public native void setBytesAmount(double bytesAmount); /* * * * * * Computation-related * * * * * */ /** - * Executes a task on the location on which the process is running. + * Executes a task on the location on which the current process is running. * - * - * @throws HostFailureException - * @throws TaskCancelledException - */ + * @throws HostFailureException + * @throws TaskCancelledException + */ public native void execute() throws HostFailureException,TaskCancelledException; - /** - * Cancels a task. - * - */ + + /** Changes the maximum CPU utilization of a computation task. Unit is flops/s. */ + public native void setBound(double bound); + + /** Cancels a task. */ public native void cancel(); - /** Deletes a task. - * - * @exception NativeException if the destruction failed. - */ - protected void finalize() throws NativeException { - destroy(); + + /** Deletes a task once the garbage collector reclaims it */ + @Override + protected void finalize() throws Throwable{ + nativeFinalize(); + bind=0; // to avoid segfaults if the impossible happens yet again making this task surviving its finalize() } - /** - * The natively implemented method to destroy a MSG task. - */ - protected native void destroy(); + protected native void nativeFinalize(); /* * * * * * Communication-related * * * * * */ - /** Send the task asynchronously on the mailbox identified by the specified name, + /** Send the task asynchronously on the specified mailbox, * with no way to retrieve whether the communication succeeded or not * */ public native void dsendBounded(String mailbox, double maxrate); - /** Send the task asynchronously on the mailbox identified by the specified name, + /** Send the task asynchronously on the specified mailbox, * with no way to retrieve whether the communication succeeded or not * */ public native void dsend(String mailbox); - + /** - * Sends the task on the mailbox identified by the specified name + * Sends the task on the specified mailbox * - * @param mailbox - * @throws TimeoutException + * @param mailbox where to send the message + * @throws TimeoutException * @throws HostFailureException * @throws TransferFailureException */ @@ -214,43 +217,41 @@ public class Task { } /** - * Sends the task on the mailbox identified by the specified name (wait at most \a timeout seconds) + * Sends the task on the specified mailbox (wait at most \a timeout seconds) * - * @param mailbox - * @param timeout - * @exception NativeException if the retrieval fails. + * @param mailbox where to send the message + * @param timeout * @throws TimeoutException * @throws HostFailureException * @throws TransferFailureException */ - public native void send(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException; - /** - * Sends the task on the mailbox identified by the specified alias (capping the sending rate to \a maxrate) + public void send(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException { + sendBounded(mailbox, timeout, -1); + } + + /** Sends the task on the specified mailbox (capping the sending rate to \a maxrate) * - * @param alias - * @param maxrate - * @throws TransferFailureException - * @throws HostFailureException - * @throws TimeoutException + * @param mailbox where to send the message + * @param maxrate + * @throws TransferFailureException + * @throws HostFailureException + * @throws TimeoutException */ - public void sendBounded(String alias, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException { - sendBounded(alias,-1,maxrate); - } + public void sendBounded(String mailbox, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException { + sendBounded(mailbox, -1, maxrate); + } -/** - * Sends the task on the mailbox identified by the specified alias (capping the sending rate to \a maxrate) with a timeout + /** Sends the task on the specified mailbox (capping the sending rate to \a maxrate) with a timeout * - * @param alias - * @param timeout - * @param maxrate - * @throws TransferFailureException - * @throws HostFailureException - * @throws TimeoutException + * @param mailbox where to send the message + * @param timeout + * @param maxrate + * @throws TransferFailureException + * @throws HostFailureException + * @throws TimeoutException */ - public void sendBounded(String alias, double timeout, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException { - sendBounded(alias,timeout,maxrate); - } + public native void sendBounded(String mailbox, double timeout, double maxrate) throws TransferFailureException, HostFailureException, TimeoutException; /** @@ -262,84 +263,82 @@ public class Task { * Sends the task on the mailbox asynchronously (capping the sending rate to \a maxrate) */ public native Comm isendBounded(String mailbox, double maxrate); - + /** * Starts listening for receiving a task from an asynchronous communication * @param mailbox + * @return a Comm handler */ public static native Comm irecv(String mailbox); + /** - * Retrieves next task from the mailbox identified by the specified name + * Retrieves next task on the mailbox identified by the specified alias * - * @param mailbox + * @param mailbox + * @return a Task */ public static Task receive(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException { - return receive(mailbox, -1.0, null); + return receive(mailbox, -1.0); } /** - * Retrieves next task on the mailbox identified by the specified name (wait at most \a timeout seconds) + * Retrieves next task on the mailbox identified by the specified alias (wait at most \a timeout seconds) * - * @param mailbox - * @param timeout + * @param mailbox + * @param timeout + * @return a Task */ - public static Task receive(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException { - return receive(mailbox, timeout, null); - } + public static native Task receive(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException; /** - * Retrieves next task sent by a given host on the mailbox identified by the specified alias + * Starts listening for receiving a task from an asynchronous communication with a capped rate + * @param mailbox + * @return a Comm handler + */ + public static native Comm irecvBounded(String mailbox, double rate); + /** + * Retrieves next task from the mailbox identified by the specified name with a capped rate * - * @param mailbox - * @param host + * @param mailbox + * @return a Task */ - public static Task receive(String mailbox, Host host) throws TransferFailureException, HostFailureException, TimeoutException { - return receive(mailbox, -1.0, host); + public static Task receiveBounded(String mailbox, double rate) throws TransferFailureException, HostFailureException, TimeoutException { + return receiveBounded(mailbox, -1.0, rate); } /** - * Retrieves next task sent by a given host on the mailbox identified by the specified alias (wait at most \a timeout seconds) + * Retrieves next task on the mailbox identified by the specified name (wait at most \a timeout seconds) with a capped rate * - * @param mailbox - * @param timeout - * @param host + * @param mailbox + * @param timeout + * @return a Task */ - public native static Task receive(String mailbox, double timeout, Host host) throws TransferFailureException, HostFailureException, TimeoutException; + public static native Task receiveBounded(String mailbox, double timeout, double rate) throws TransferFailureException, HostFailureException, TimeoutException; + + + /** * Tests whether there is a pending communication on the mailbox identified by the specified alias, and who sent it - */ - public native static int listenFrom(String mailbox); + */ + public static native int listenFrom(String mailbox); /** - * Listen whether there is a waiting task on the mailbox identified by the specified alias - */ - public native static boolean listen(String mailbox); + * Listen whether there is a task waiting (either for a send or a recv) on the mailbox identified by the specified alias + */ + public static native boolean listen(String mailbox); - /** - * Counts the number of tasks waiting to be received on the \a mailbox identified by the specified alia and sended by the specified \a host. - */ - public native static int listenFromHost(String alias, Host host); - /** * Class initializer, to initialize various JNI stuff */ public static native void nativeInit(); static { - Msg.nativeInit(); + org.simgrid.NativeLib.nativeInit(); nativeInit(); } public double getMessageSize() { return this.messageSize; } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } }