Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add File support and an example to cover it.
authorSamuel Lepetit <samuel.lepetit@inria.fr>
Tue, 12 Jun 2012 19:32:10 +0000 (21:32 +0200)
committerSamuel Lepetit <samuel.lepetit@inria.fr>
Tue, 12 Jun 2012 19:32:10 +0000 (21:32 +0200)
CMakeLists.txt
examples/io/IO.java [new file with mode: 0644]
examples/io/Node.java [new file with mode: 0644]
examples/io/storage.xml [new file with mode: 0644]
org/simgrid/msg/File.java [new file with mode: 0644]
src/jmsg_file.c [new file with mode: 0644]
src/jmsg_file.h [new file with mode: 0644]

index 327131a..8f032ed 100644 (file)
@@ -82,22 +82,25 @@ set(JMSG_C_SRC
        src/jmsg.h
        src/jmsg_comm.c
        src/jmsg_comm.h
+       src/jmsg_file.c
+       src/jmsg_file.h
        src/jmsg_host.c
        src/jmsg_host.h
        src/jmsg_process.c
        src/jmsg_process.h
-       src/jmsg_task.c
-       src/jmsg_task.h
-       src/jmsg_synchro.c
-       src/jmsg_synchro.h
        src/jmsg_rngstream.c
        src/jmsg_rngstream.h
+       src/jmsg_synchro.c
+       src/jmsg_synchro.h
+       src/jmsg_task.c
+       src/jmsg_task.h
 )
 
 set(JMSG_JAVA_SRC
        org/simgrid/msg/Host.java
        org/simgrid/msg/HostFailureException.java       
        org/simgrid/msg/HostNotFoundException.java      
+    org/simgrid/msg/File.java
        org/simgrid/msg/JniException.java
        org/simgrid/msg/Msg.java
        org/simgrid/msg/MsgException.java
@@ -139,6 +142,8 @@ set(JAVA_EXAMPLES
        examples/commTime/Master.java
        examples/commTime/Slave.java
        examples/commTime/CommTimeTest.java
+       examples/io/IO.java
+       examples/io/Node.java
        examples/masterslave/FinalizeTask.java
        examples/masterslave/Forwarder.java
        examples/masterslave/Master.java
@@ -267,8 +272,9 @@ add_custom_command(
   COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/bittorrent/*.java
   COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/chord/*.java
   COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/commTime/*.java
-       COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/masterslave/*.java
-       COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/master_slave_bypass/*.java
+  COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/io/*.java
+  COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/masterslave/*.java
+  COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/master_slave_bypass/*.java
   COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/master_slave_kill/*.java
        COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/migration/*.java
   COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/mutualExclusion/centralized/*.java                                      
diff --git a/examples/io/IO.java b/examples/io/IO.java
new file mode 100644 (file)
index 0000000..6a6674f
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * 2012. 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 io;
+
+import org.simgrid.msg.Host;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.MsgException;
+/**
+ * This example demonstrates of how to use the other
+ * kind of resources, such as disk or GPU. These resources are quite
+ * experimental for now, but here we go anyway.
+ */
+public class IO {
+    public static void main(String[] args) throws MsgException {       
+               Msg.init(args);
+               if(args.length < 1) {
+                       Msg.info("Usage   : IO platform_file ");
+               Msg.info("example : IO platform.xml ");
+               System.exit(1);
+           }    
+               Msg.createEnvironment(args[0]);
+               
+               Host[] hosts = Host.all();
+               
+               Msg.info("Number of hosts:" + hosts.length);
+               for (int i = 0; i < hosts.length && i < 4; i++) {
+                       new io.Node(hosts[i],i).start();
+               }
+               
+               Msg.run();              
+    }
+}
\ No newline at end of file
diff --git a/examples/io/Node.java b/examples/io/Node.java
new file mode 100644 (file)
index 0000000..5afc600
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 2012. 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 io;
+
+import org.simgrid.msg.File;
+import org.simgrid.msg.Host;
+import org.simgrid.msg.HostNotFoundException;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.MsgException;
+import org.simgrid.msg.Process;
+
+public class Node extends Process {
+       private static String FILENAME1 = "/home/user/Install/simgrid/doc/simgrid/examples/platforms/g5k.xml";
+       private static String FILENAME2 = "/home/user/Install/simgrid/doc/simgrid/examples/platforms/One_cluster_no_backbone.xml";
+       private static String FILENAME3 = "/home/user/Install/simgrid/doc/simgrid/examples/platforms/g5k_cabinets.xml";
+       private static String FILENAME4 = "/home/user/Install/simgrid/doc/simgrid/examples/platforms/nancy.xml";
+                       
+       protected int number;
+               
+       public Node(Host host, int number) throws HostNotFoundException {
+               super(host, Integer.toString(number), null);
+               this.number = number;
+       }       
+       public void main(String[] args) throws MsgException {
+               String mount = "C:";
+               String filename;
+               switch (number) {
+                       case 0:
+                               filename = FILENAME1;
+                       break;
+                       case 1:
+                               filename = FILENAME2;
+                       break;
+                       case 2:
+                               filename = FILENAME3;
+                       break;
+                       case 3:
+                               filename = FILENAME4;
+                       break;
+                       default:
+                               filename = FILENAME1;
+               }
+               Msg.info("Open file " + filename);
+               File file = new File(mount,filename, "rw");
+
+               long read = file.read(mount,10000000,1);
+               Msg.info("Having read " + read + " on " + filename);
+               
+               long write = file.read(mount,100000,1);
+               Msg.info("Having write " + write + " on " + filename);
+
+               read = file.read(mount,10000000,1);
+               Msg.info("Having read " + read + " on " + filename);            
+       }
+}
\ No newline at end of file
diff --git a/examples/io/storage.xml b/examples/io/storage.xml
new file mode 100644 (file)
index 0000000..58fca89
--- /dev/null
@@ -0,0 +1,58 @@
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
+
+<platform version="3">
+
+       <AS id="AS0" routing="Full">
+
+               <storage_type id="samsung" model="RAID5" content="content/storage_content.txt" size="500">
+                       <prop id="Bwrite" value="30000000" /> <!-- 30Mo/s -->
+                       <prop id="Bread" value="100000000" /> <!-- 100Mo/s -->
+                       <prop id="Bconnection" value="150000000" /> <!-- 150Mo/s -->
+               </storage_type>
+
+               <storage_type id="crucial" model="SSD" content="content/storage_content.txt" size="500">
+                       <prop id="Bwrite" value="30000000" />
+                       <prop id="Bread" value="100000000" />
+                       <prop id="Bconnection" value="150000000" />
+               </storage_type>
+
+               <storage_type id="wdigital" model="RAID0" content="content/storage_content.txt" size="500">
+                       <prop id="Bwrite" value="30000000" />
+                       <prop id="Bread" value="100000000" />
+                       <prop id="Bconnection" value="150000000" />
+               </storage_type>
+
+               <storage id="Disk1" typeId="crucial"/>
+               <storage id="Disk2" typeId="samsung"/>
+               <storage id="Disk3" typeId="wdigital"/>
+               <storage id="Disk4" typeId="wdigital"/>
+
+               <host id="bob" power="1000000000">
+                       <mount id="Disk1" name="C:"/>                   
+               </host>         
+               
+               <host id="alice" power="1000000000">
+                       <mount id="Disk2" name="C:"/>
+               </host>
+
+               <host id="carl" power="1000000000">             
+                       <mount id="Disk3" name="C:"/>           
+               </host>
+               
+               <host id="denise" power="1000000000">
+                       <mount id="Disk4" name="C:"/>   
+               </host>
+
+               <link id="link1" bandwidth="125000000" latency="5E-5" />
+               <link id="link2" bandwidth="125000000" latency="5E-5" />
+               <link id="link3" bandwidth="125000000" latency="5E-5" />
+       
+               <route src="bob" dst="alice" symmetrical="YES">
+                       <link_ctn id="link1" />
+                       <link_ctn id="link2" />
+                       <link_ctn id="link3" />
+               </route>        
+
+       </AS>
+</platform>
diff --git a/org/simgrid/msg/File.java b/org/simgrid/msg/File.java
new file mode 100644 (file)
index 0000000..0f85eb4
--- /dev/null
@@ -0,0 +1,66 @@
+package org.simgrid.msg;
+/**
+* Copyright 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.
+*
+*/
+
+public class File {
+       protected String storage;
+       /**
+        * Represents the bind between the java comm and the
+        * native C comm. You must never access it, since it is 
+        * automatically set.
+        */
+       public long bind = 0;
+       /**
+        * Constructor, opens the file.
+        * @param storage is the name where you can find the stream 
+        * @param path is the file location on the storage 
+        * @param mode points to a string beginning with one of the following sequences (Additional characters may follow these sequences.): r Open text file for reading. The stream is positioned at the beginning of the file. r+ Open for reading and writing. The stream is positioned at the beginning of the file. w Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file. w+ Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file. a Open for appending (writing at end of file). The file is created if it does not exist. The stream is positioned at the end of the file. a+ Open for reading and appending (writing at end of file). The file is created if it does not exist. The initial file position for reading is at the beginning of the file, but output is always appended to the end of the file.
+        */
+       public File(String storage, String path, String mode) {
+               this.storage = storage;
+               open(storage, path, mode);
+       }
+       protected void finalize() {
+               close(storage);
+       }
+       /**
+        * Opens the file whose name is the string pointed to by path. 
+        * @param storage is the name where you can find the stream 
+        * @param path is the file location on the storage
+        * @param mode points to a string beginning with one of the following sequences (Additional characters may follow these sequences.): r Open text file for reading. The stream is positioned at the beginning of the file. r+ Open for reading and writing. The stream is positioned at the beginning of the file. w Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file. w+ Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file. a Open for appending (writing at end of file). The file is created if it does not exist. The stream is positioned at the end of the file. a+ Open for reading and appending (writing at end of file). The file is created if it does not exist. The initial file position for reading is at the beginning of the file, but output is always appended to the end of the file.
+        */
+       protected native void open(String storage, String path, String mode);
+       /**
+        * Read elements of a file. 
+        * @param storage is the name where you can find the stream
+        * @param size of each element
+        * @param nMemb is the number of elements of data to write 
+        */
+       public native long read(String storage, long size, long nMemb);
+       /**
+        * Write elements into a file. 
+        * @param storage is the name where you can find the stream 
+        * @param size of each element  
+        * @param nMemb is the number of elements of data to write 
+        */
+       public native long write(String storage, long size, long nMemb);
+       /**
+        * Close the file.      
+        * @param storage is the name where you can find the stream 
+        */
+       public native void close(String storage);
+       
+       /**
+        * Class initializer, to initialize various JNI stuff
+        */
+       public static native void nativeInit();
+       static {
+               nativeInit();
+       }       
+}
\ No newline at end of file
diff --git a/src/jmsg_file.c b/src/jmsg_file.c
new file mode 100644 (file)
index 0000000..3695fb8
--- /dev/null
@@ -0,0 +1,76 @@
+/* Functions related to the java file API.                            */
+/* Copyright (c) 2012. 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. */
+#include "jmsg_file.h"
+#include "jxbt_utilities.h"
+void jfile_bind(JNIEnv *env, jobject jfile, msg_file_t stream) {
+  (*env)->SetLongField(env, jfile, jfile_field_bind, (jlong) (long) (stream));
+}
+
+msg_file_t jfile_get_native(JNIEnv *env, jobject jfile) {
+       msg_file_t file = (msg_file_t)(*env)->GetLongField(env, jfile, jfile_field_bind);
+       return file;
+}
+
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_File_nativeInit(JNIEnv *env, jclass cls) {
+       jclass class_File = (*env)->FindClass(env, "org/simgrid/msg/File");
+       jfile_field_bind = jxbt_get_jfield(env , class_File, "bind", "J");
+       xbt_assert((jfile_field_bind != NULL), "Can't find \"bind\" field in File class.");
+}
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_File_open(JNIEnv *env, jobject jfile, jobject jstorage, jobject jpath, jobject jmode) {
+
+       const char *storage = (*env)->GetStringUTFChars(env, jstorage, 0);
+       const char *path = (*env)->GetStringUTFChars(env, jpath, 0);
+       const char *mode = (*env)->GetStringUTFChars(env, jmode, 0);
+
+       msg_file_t file = MSG_file_open(storage, path, mode);
+
+       jfile_bind(env, jfile, file);
+
+       (*env)->ReleaseStringUTFChars(env, jstorage, storage);
+       (*env)->ReleaseStringUTFChars(env, jpath, path);
+       (*env)->ReleaseStringUTFChars(env, jmode, mode);
+}
+JNIEXPORT jlong JNICALL
+Java_org_simgrid_msg_File_read(JNIEnv *env, jobject jfile, jobject jstorage, jlong jsize, jlong jnmemb) {
+       msg_file_t file = jfile_get_native(env, jfile);
+
+       const char *storage = (*env)->GetStringUTFChars(env, jstorage, 0);
+
+       size_t n = MSG_file_read(storage, NULL,(size_t)jsize, (size_t)jnmemb, file);
+
+       (*env)->ReleaseStringUTFChars(env, jstorage, storage);
+
+       return (jlong)n;
+}
+
+JNIEXPORT jlong JNICALL
+Java_org_simgrid_msg_File_write(JNIEnv *env, jobject jfile, jobject jstorage, jlong jsize, jlong jnmemb) {
+       msg_file_t file = jfile_get_native(env, jfile);
+
+       const char *storage = (*env)->GetStringUTFChars(env, jstorage, 0);
+
+       size_t n = MSG_file_write(storage, NULL, (size_t)jsize, (size_t)jnmemb, file);
+
+       (*env)->ReleaseStringUTFChars(env, jstorage, storage);
+
+       return (jlong)n;
+}
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_File_close(JNIEnv *env, jobject jfile, jobject jstorage) {
+       msg_file_t file = jfile_get_native(env, jfile);
+
+       const char *storage = (*env)->GetStringUTFChars(env, jstorage, 0);
+
+       MSG_file_close(storage, file);
+       jfile_bind(env, jfile, NULL);
+
+       (*env)->ReleaseStringUTFChars(env, jstorage, storage);
+
+}
+
diff --git a/src/jmsg_file.h b/src/jmsg_file.h
new file mode 100644 (file)
index 0000000..4202ea2
--- /dev/null
@@ -0,0 +1,50 @@
+/* Functions related to the java file API.                            */
+/* Copyright (c) 2012. 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. */
+
+#ifndef MSG_JFILE_H
+#define MSG_JFILE_H
+#include <jni.h>
+#include "msg/msg.h"
+
+jfieldID jfile_field_bind;
+
+void jfile_bind(JNIEnv *env, jobject jfile, msg_file_t stream);
+msg_file_t jfile_get_native(JNIEnv *env, jobject jfile);
+/**
+ * Class                       org_simgrid_msg_File
+ * Method                      nativeInit
+ * Signature   ()V
+ */
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_File_nativeInit(JNIEnv*, jclass);
+/**
+ * Class                       org_simgrid_msg_File
+ * Method                      open
+ * Signature   (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_File_open(JNIEnv*, jobject, jobject, jobject, jobject);
+/**
+ * Class                       org_simgrid_msg_File
+ * Method                      read
+ */
+JNIEXPORT jlong JNICALL
+Java_org_simgrid_msg_File_read(JNIEnv*, jobject, jobject, jlong, jlong);
+/**
+ * Class                       org_simgrid_msg_File
+ * Method                      write
+ */
+JNIEXPORT jlong JNICALL
+Java_org_simgrid_msg_File_write(JNIEnv*, jobject, jobject, jlong, jlong);
+/**
+ * Class                       org_simgrid_msg_File
+ * Method                      close
+ */
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_File_close(JNIEnv*, jobject, jobject);
+
+#endif