FileDB2.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.data.experiment.extdata;
00002 
00003 import java.io.IOException;
00004 import java.io.RandomAccessFile;
00005 import java.nio.channels.FileChannel;
00006 
00007 import edu.rice.cs.hpc.data.util.Constants;
00008 import edu.rice.cs.hpc.data.util.LargeByteBuffer;
00009 
00010 public class FileDB2 implements IFileDB 
00011 {
00012     //-----------------------------------------------------------
00013     // Global variables
00014     //-----------------------------------------------------------
00015     
00016     private int type = Constants.MULTI_PROCESSES | Constants.MULTI_THREADING; // default is hybrid
00017     
00018     private LargeByteBuffer masterBuff;
00019     
00020     private int numFiles = 0;
00021     private String valuesX[];
00022     private long offsets[];
00023     
00024     private RandomAccessFile file; 
00025 
00026     public void open(String filename, int headerSize, int recordSz)  throws IOException 
00027     {
00028         
00029         if (filename != null) {
00030             
00031             //---------------------------------------------
00032             // test file version
00033             //---------------------------------------------
00034             
00035             this.setData(filename, 24, recordSz);
00036         }
00037     }
00038     
00039     /***
00040      * retrieve the array of process IDs
00041      * 
00042      * @return
00043      */
00044     public String []getRankLabels() {
00045         return valuesX;
00046     }
00047     
00048 
00049     public int getNumberOfRanks() 
00050     {
00051         return this.numFiles;
00052     }
00053     
00054     public long[] getOffsets() 
00055     {
00056         return this.offsets;
00057     }
00058     
00059     public LargeByteBuffer getMasterBuffer()
00060     {
00061         return this.masterBuff;
00062     }
00063     
00064     /***
00065      * assign data
00066      * @param f: array of files
00067      * @throws IOException 
00068      */
00069     private void setData(String filename, int headerSize, int recordSz)
00070             throws IOException {
00071         
00072         file = new RandomAccessFile(filename, "r");
00073         final FileChannel f = file.getChannel();
00074         masterBuff = new LargeByteBuffer(f, headerSize, recordSz);
00075 
00076         this.type = masterBuff.getInt(0);
00077         this.numFiles = masterBuff.getInt(Constants.SIZEOF_INT);
00078         
00079         valuesX = new String[numFiles];
00080         offsets = new long[numFiles];
00081         
00082         long current_pos = Constants.SIZEOF_INT * 2;
00083         
00084         // get the procs and threads IDs
00085         for(int i=0; i<numFiles; i++) {
00086 
00087             final int proc_id = masterBuff.getInt(current_pos);
00088             current_pos += Constants.SIZEOF_INT;
00089             final int thread_id = masterBuff.getInt(current_pos);
00090             current_pos += Constants.SIZEOF_INT;
00091             
00092             offsets[i] = masterBuff.getLong(current_pos);
00093             current_pos += Constants.SIZEOF_LONG;
00094             
00095             //--------------------------------------------------------------------
00096             // adding list of x-axis 
00097             //--------------------------------------------------------------------          
00098             
00099             String x_val;
00100             if (this.isHybrid()) 
00101             {
00102                 x_val = String.valueOf(proc_id) + "." + String.valueOf(thread_id);
00103             } else if (isMultiProcess()) 
00104             {
00105                 x_val = String.valueOf(proc_id);                    
00106             } else if (isMultiThreading()) 
00107             {
00108                 x_val = String.valueOf(thread_id);
00109             } else {
00110                 // temporary fix: if the application is neither hybrid nor multiproc nor multithreads,
00111                 // we just print whatever the order of file name alphabetically
00112                 // this is not the ideal solution, but we cannot trust the value of proc_id and thread_id
00113                 x_val = String.valueOf(i);
00114             }
00115             
00116             valuesX[i] = x_val;
00117         }
00118         //f.close();
00119         //file.close();
00120     }
00121 
00122     public int      getParallelismLevel()
00123     {
00124         return (isHybrid()? 2 : 1);
00125     }
00126 
00132     public boolean isMultiProcess() {
00133         return (type & Constants.MULTI_PROCESSES) != 0;
00134     }
00135     
00141     public boolean isMultiThreading() {
00142         return (type & Constants.MULTI_THREADING) != 0;
00143     }
00144     
00145     /***
00146      * Check if the application is a hybrid program (MPI+OpenMP)
00147      * 
00148      * @return
00149      */
00150     public boolean isHybrid() {
00151         return (isMultiProcess() && isMultiThreading());
00152     }
00153 
00154     /***
00155      * Disposing native resources
00156      */
00157     public void dispose() {
00158         if (masterBuff != null)
00159             masterBuff.dispose();
00160 
00161         if (file != null) {
00162             try {
00163                 // ------------------------------------------------------
00164                 // need to close the file and its file channel
00165                 // somehow this can free the memory
00166                 // ------------------------------------------------------
00167                 file.close();
00168             } catch (IOException e) {
00169                 // TODO Auto-generated catch block
00170                 e.printStackTrace();
00171             }
00172         }
00173     }
00174 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1