Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Many modifications in order to make a more efficient library for GNode creation
[mapping.git] / src / and / Mapping / Utils.java
index 2127186..57a87e2 100644 (file)
@@ -1,6 +1,5 @@
 package and.Mapping ;
 
-
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
@@ -9,11 +8,6 @@ import java.io.PrintWriter;
 import java.net.InetAddress;
 import java.util.ArrayList;
 
-import org.hyperic.sigar.CpuInfo;
-import org.hyperic.sigar.Mem;
-import org.hyperic.sigar.Sigar;
-import org.hyperic.sigar.SigarException;
-
 import com.thoughtworks.xstream.XStream;
 import com.thoughtworks.xstream.io.xml.DomDriver;
 
@@ -25,12 +19,6 @@ import com.thoughtworks.xstream.io.xml.DomDriver;
  */
 public class Utils 
 {
-//     public static String getOS()
-//     {
-//             return System.getProperty( "os.name" ) ;
-//     }
-       
-       
        /**
         * Creation of the representation of the node in the Mapping point of view. It needs
         * some information about the computing node, which will be exploited by mapping
@@ -39,126 +27,37 @@ public class Utils
         */
        public static GNode createGNode()
        {
+               /** Using the Linpack class **/
+               Linpack linpack = new Linpack() ;
+               
+               /**  **/
                GNode n = new GNode() ;
                int nbCore = 0 ;
                int frequency = 0 ;
+               int mflops = 0 ;
                int memory = 0 ;
                String name = "" ;
                
-//             InputStream ips ; 
-//             InputStreamReader ipsr ;
-//             BufferedReader br ;
-//             String ligne ;
-//             
-//             
-//             String fichier_cpu = "" ;
-//             String fichier_mem = "" ;
-//             
-//             
-//             if( getOS().equals( "Linux" ) )
-//             {
-//                     fichier_cpu = "/proc/cpuinfo" ;
-//                     fichier_mem = "/proc/meminfo" ;         
-//             
-//                     /* Lecture des informations processeur */
-//                     try{
-//                             ips = new FileInputStream( fichier_cpu ) ; 
-//                             ipsr = new InputStreamReader( ips ) ;
-//                             br = new BufferedReader( ipsr ) ;
-//                     
-//                     
-//                             while( ( ligne = br.readLine() ) != null )
-//                             {
-//                                     if( ligne.contains( "processor" ) )
-//                                     {
-//                                             nb_coeurs ++ ;
-//                                     }       
-//                             
-//                                     if( ligne.contains("cpu MHz") )
-//                                     {
-//                                             String tab[] = new String[2] ;
-//
-//                                             tab = ligne.split( ":" ) ;
-//                                     
-//                                             frequence = ( int ) Double.parseDouble( tab[1] ) ;
-//                                     }
-//
-//                             }
-//                             
-//                             br.close() ;
-//                             ipsr.close() ;
-//                             ips.close() ;
-//                     
-//                     } catch( Exception e ) {
-//                             System.out.println( e.toString() ) ;
-//                     }
-//             
-//             
-//                     /* Lecture des informations mémoire */
-//                     try {
-//                             ips = new FileInputStream( fichier_mem ) ; 
-//                             ipsr = new InputStreamReader( ips ) ;
-//                             br = new BufferedReader( ipsr ) ;
-//                     
-//                             while( ( ligne = br.readLine() ) != null )
-//                             {                               
-//                                     if( ligne.contains("MemTotal") )
-//                                     {
-//                                             String tab[] = new String[2] ;
-//                                     
-//                                             tab = ligne.split( ":" ) ;
-//                                             ligne = tab[1].trim() ;
-//                                             tab = ligne.split( " " ) ;
-//                                             memoire = ( int ) Double.parseDouble( tab[0] ) ;
-//                                     }
-//
-//                             }
-//                     
-//                             br.close() ;
-//                             ipsr.close() ;
-//                             ips.close() ;
-//                     
-//                     } catch( Exception e ) {
-//                             System.out.println( e.toString() ) ;
-//                     }
-//             
-//             }
                
-               /* Creating the hardware information retriever */
-               Sigar sigar = new Sigar() ;
+               /** CPU information **/
                
-               /* CPU information */
-               CpuInfo cpuinfo[] = null ;
-               try {
-                       cpuinfo = sigar.getCpuInfoList();
-               } catch (SigarException e) {
-                       System.err.println( "Unable to retrieve CPU information !" ) ;
-                       e.printStackTrace();
-                       System.exit( 1 ) ;
-               }
+               /* Amount of available computing cores */
+               nbCore = Runtime.getRuntime().availableProcessors() ;
+               
+               /* Average MegaFlops of each core */
+               double tmp_mflops = 0 ;
+               int loop = 10 ;
                
-               int tmp = 0 ;
-               for( int i = 0 ; i < cpuinfo.length ; i++ )
+               for( int i = 0 ; i < loop ; i++ )
                {
-                       nbCore++ ;
-                       tmp+= cpuinfo[i].getMhz() ;
+                       tmp_mflops += linpack.getMFlops() ;
+                       System.gc() ;
                }
+               mflops = (int) tmp_mflops / loop ;
                
-               /* The frequency is the average of cores frequencies */
-               frequency = tmp / nbCore ;
-               
-               
-               /* Memory information */
-               Mem mem = null ;
-               try {
-                       mem = sigar.getMem() ;
-               } catch (SigarException e) {
-                       System.err.println( "Unable to retrieve memory information !" ) ;
-                       e.printStackTrace();
-                       System.exit( 1 ) ;
-               }
                
-               memory = (int)mem.getFree()/1000 ;
+               /** Memory information **/
+               memory = (int) Runtime.getRuntime().maxMemory() / 1024 / 1024 ;
                
                
                /* Host name */
@@ -174,6 +73,7 @@ public class Utils
                
                /* Updating node information */
                n.setFrequency( frequency ) ;
+               n.setMFlops( mflops ) ;
                n.setMemory( memory ) ;
                n.setNb_cores( nbCore ) ;
                n.setName( name ) ;