hacks to fix issues with benchmarks...
authorbdemsky <bdemsky>
Thu, 29 Jan 2009 04:52:12 +0000 (04:52 +0000)
committerbdemsky <bdemsky>
Thu, 29 Jan 2009 04:52:12 +0000 (04:52 +0000)
and to optimize the transRead call

Robust/src/Benchmarks/Prefetch/2DConv/dsm/Convolution.java
Robust/src/Benchmarks/Prefetch/2DConv/javasingle/Convolution.java
Robust/src/Benchmarks/Prefetch/Em3d/dsm/Node2.java
Robust/src/Benchmarks/Prefetch/Em3d/javasingle/Node2.java
Robust/src/Benchmarks/Prefetch/run.sh
Robust/src/IR/Flat/BuildCode.java
Robust/src/Runtime/DSTM/interface/addPrefetchEnhance.c
Robust/src/Runtime/DSTM/interface/clookup.c
Robust/src/Runtime/DSTM/interface/clookup2.c
Robust/src/Runtime/DSTM/interface/clookup2.h
Robust/src/Runtime/DSTM/interface/trans.c

index 91e7f856eb8c4e56202a141c627259f166ea4b72..3c97e4d4277e61b02d7d4ede373493753cfeec1f 100644 (file)
@@ -14,9 +14,9 @@ public class Convolution extends Thread {
     int kernelHeight = 5;
     int kernelWidth = 5;
     double[][] kernel = new double[kernelHeight][kernelWidth];
+    initKernel(kernel);
 
     atomic {
-      initKernel(kernel);
       double tempinput[][] = img.inputImage;
       double tempout[][] = img.outputImage;
 
@@ -31,11 +31,12 @@ public class Convolution extends Thread {
         double tout[] = tempout[i];
         tinput0 = tinput1; tinput1=tinput2; tinput2=tinput3; tinput3=tinput4; tinput4=tempinput[l];
         for(int j=y0;j<y1;++j){
-          tout[j] = 0;
+          double s=0;
           for(int b=0;b<kernelHeight;++b){
-            tout[j] = tout[j] + (tinput0[j+b] * kernel[0][b] + tinput1[j+b] * kernel[1][b] + tinput2[j+b]*kernel[2][b] +
+            s+=(tinput0[j+b] * kernel[0][b] + tinput1[j+b] * kernel[1][b] + tinput2[j+b]*kernel[2][b] +
                 tinput3[j+b]*kernel[3][b] + tinput4[j+b]*kernel[4][b]);
           }
+         tout[j]=s;
         }
       }
     }
@@ -112,7 +113,7 @@ public class Convolution extends Thread {
   }
 
   //define 5X5 Gaussian kernel
-  public void initKernel(double[][] kernel) {
+    public static void initKernel(double[][] kernel) {
     kernel[0][0] = 1/256.0;
     kernel[0][1] = 4/256.0;
     kernel[0][2] = 6/256.0;
index 6ccef41cd4b5255b69fbb7aade90587f6db83385..2fe92a0e7194775d7a0f6470b7e5d1c5e03a52b3 100644 (file)
@@ -29,11 +29,13 @@ public class Convolution {
       double tout[] = tempout[i];
       tinput0 = tinput1; tinput1=tinput2; tinput2=tinput3; tinput3=tinput4; tinput4=tempinput[l];
       for(int j=y0;j<y1;++j){
-        tout[j] = 0;
+         double s=0;
         for(int b=0;b<kernelHeight;++b){
-          tout[j] = tout[j] + (tinput0[j+b] * kernel[0][b] + tinput1[j+b] * kernel[1][b] + tinput2[j+b]*kernel[2][b] +
-              tinput3[j+b]*kernel[3][b] + tinput4[j+b]*kernel[4][b]);
+          s += tinput0[j+b] * kernel[0][b] + tinput1[j+b] * kernel[1][b] + tinput2[j+b]*kernel[2][b] +
+              tinput3[j+b]*kernel[3][b] + tinput4[j+b]*kernel[4][b];
         }
+        tout[j] = s;
+
       }
     }
   }
@@ -79,7 +81,7 @@ public class Convolution {
   }
 
   //define 5X5 Gaussian kernel
-  public void initKernel(double[][] kernel) {
+  public static void initKernel(double[][] kernel) {
     kernel[0][0] = 1/256.0;
     kernel[0][1] = 4/256.0;
     kernel[0][2] = 6/256.0;
index 8b568d52a2b58f9b8b3b797700148e954e401dc5..ac20cea215bf67ef72aa63738ba3b9e4755415bc 100644 (file)
@@ -50,7 +50,8 @@ public class Node {
      * @param nodeTable the list of nodes to choose from.
      **/
     public void makeUniqueNeighbors(EVector[] reversetable,Node[] nodeTable, Random rand, int begin, int end) {
-       int len=toNodes.length;
+       Node [] toN=toNodes;
+       int len=toN.length;
        for (int filled = 0; filled < len; filled++) {
            int k;
            Node otherNode;
@@ -70,13 +71,13 @@ public class Node {
                otherNode = nodeTable[index];
                
                for (k = 0; (k < filled) && (isBreak==false); k++) {
-                   if (otherNode == toNodes[k]) 
+                   if (otherNode == toN[k]) 
                        isBreak = true;
                }
            } while (k < filled);
            
            // other node is definitely unique among "filled" toNodes
-           toNodes[filled] = otherNode;
+           toN[filled] = otherNode;
            
            // update fromCount for the other node
            if (reversetable[index]==null)
index 07152b2e2280ee331ccdb321d34cfb6b8cc9d16d..74642cce40cc8c1c7e0cc87bff9d5afc530af19d 100644 (file)
@@ -50,7 +50,8 @@ public class Node {
      * @param nodeTable the list of nodes to choose from.
      **/
     public void makeUniqueNeighbors(EVector[] reversetable,Node[] nodeTable, Random rand, int begin, int end) {
-       int len=toNodes.length;
+       Node[] toN=toNodes;
+       int len=toN.length;
        for (int filled = 0; filled < len; filled++) {
            int k;
            Node otherNode;
@@ -70,13 +71,13 @@ public class Node {
                otherNode = nodeTable[index];
                
                for (k = 0; (k < filled) && (isBreak==false); k++) {
-                   if (otherNode == toNodes[k]) 
+                   if (otherNode == toN[k]) 
                        isBreak = true;
                }
            } while (k < filled);
            
            // other node is definitely unique among "filled" toNodes
-           toNodes[filled] = otherNode;
+           toN[filled] = otherNode;
            
            // update fromCount for the other node
            if (reversetable[index]==null)
index ba24705fe6bc3147b5ce3a1493b5b59d241646ac..c473a47858ebe9979203f9640f48abf6b2addfc2 100755 (executable)
@@ -2,7 +2,7 @@
 
 #set -x
 MACHINELIST='dc-1.calit2.uci.edu dc-2.calit2.uci.edu dc-3.calit2.uci.edu dc-4.calit2.uci.edu dc-5.calit2.uci.edu dc-6.calit2.uci.edu dc-7.calit2.uci.edu dc-8.calit2.uci.edu'
-benchmarks='1152fft2d 40962dconv 20482dconv 600mmver moldynverA em3dver40001306'
+benchmarks='1152fft2d 40962dconv 20482dconv 800mmver moldynverA em3dver40001306'
 
 LOGDIR=~/research/Robust/src/Benchmarks/Prefetch/runlog
 TOPDIR=`pwd`
@@ -129,9 +129,9 @@ function callrun {
 for count in 2 4 6 8
 do
 echo "------- Running $count threads $BMDIR non-prefetch + non-cache on $count machines -----"
-run 1 $count $NONPREFETCH_NONCACHE
+#run 1 $count $NONPREFETCH_NONCACHE
 echo "------- Running $count threads $BMDIR prefetch on $count machines -----"
-run 1 $count $PREFETCH
+#run 1 $count $PREFETCH
 done
 
 cd $TOPDIR
index e07a04594881fbde62115f73225ea248a2df25a1..402e99f67ae56b14438e6a02c19a2b2ef4a5840b 100644 (file)
@@ -1310,9 +1310,9 @@ public class BuildCode {
 
     if ((state.THREAD||state.DSM)&&GENERATEPRECISEGC) {
       if (state.DSM&&lb.isAtomic())
-       output.println("checkcollect2(&"+localsprefix+",trans);");
+       output.println("if (needtocollect) checkcollect2(&"+localsprefix+",trans);");
       else
-       output.println("checkcollect(&"+localsprefix+");");
+       output.println("if (needtocollect) checkcollect(&"+localsprefix+");");
     }
 
     /* Do the actual code generation */
index d88e077d89489b410cf2b42bedf3547f0c7391e7..fedcb919d27eb04c23cbc37182245803d3d59c0a 100644 (file)
@@ -57,6 +57,7 @@ void handleDynPrefetching(int numLocal, int ntuples, int siteid) {
   }
 }
 
+#if 1
 /* This function clears from prefetch cache those
  * entries that caused a transaction abort */
 void cleanPCache(transrecord_t *record) {
@@ -79,6 +80,27 @@ void cleanPCache(transrecord_t *record) {
     }
   }
 }
+#else
+/* This function clears from prefetch cache those
+ * entries that caused a transaction abort */
+void cleanPCache(transrecord_t *record) {
+  transrecord_t *rec = record;
+  unsigned int size = rec->lookupTable->size;
+  struct chashentry *ptr = rec->lookupTable->table;
+  int i;
+  for(i = 0; i < size; i++) {
+    struct chashentry *curr = &ptr[i]; //for each entry in the cache lookupTable
+    if(curr->key == 0)
+      continue;
+    objheader_t *header1, *header2;
+    /* Not found in local machine's object store and found in prefetch cache */
+    if((header1 = mhashSearch(curr->key)) == NULL && ((header2 = prehashSearch(curr->key)) != NULL)) {
+      /* Remove from prefetch cache */
+      prehashRemove(curr->key);
+    }
+  }
+}
+#endif
 
 /* This function updates the prefetch cache with
  * entries from the transaction cache when a
index 0f6fa5c0e189feddad71717f6f6f09731a889de3..fee16fa73cdc01930b603b1c184734dfa1d0b6f8 100644 (file)
@@ -71,12 +71,13 @@ INLINE void * chashSearch(chashtable_t *table, unsigned int key) {
   //REMOVE HASH FUNCTION CALL TO MAKE SURE IT IS INLINED HERE
   chashlistnode_t *node = &table->table[(key & table->mask)>>1];
 
-  while(node != NULL) {
+  do {
     if(node->key == key) {
       return node->val;
     }
     node = node->next;
-  }
+  } while(node != NULL);
+
   return NULL;
 }
 
index 4fab4eb08378505ea994887512c9fc16fd9c527a..4ceb62219f5b89ab5f84bb94d2e4b48807209b0d 100644 (file)
@@ -1,4 +1,4 @@
-#include "clookup2.h"
+#include "clookup.h"
 #define INLINE    inline __attribute__((always_inline))
 
 chashtable_t *chashCreate(unsigned int size, float loadfactor) {
@@ -28,51 +28,63 @@ chashtable_t *chashCreate(unsigned int size, float loadfactor) {
 }
 
 //Finds the right bin in the hash table
-static INLINE unsigned int chashFunction(chashtable_t *table, unsigned int key) {
-  return ( key & (table->mask))>>1; //throw away low order bit
+static INLINE unsigned int chashFunction(chashtable_t *table, unsigned int key, unsigned int i) {
+  return ((key+i*331) & table->mask)>>1; //throw away low order bit
 }
 
 //Store objects and their pointers into hash
 void chashInsert(chashtable_t *table, unsigned int key, void *val) {
-  unsigned int newsize;
-  unsigned int index;
-  struct chashentry *node;
+  struct chashentry *node = &table->table[(key & table->mask)>>1];
+  unsigned int ne=table->numelements++;
+  unsigned int i;
 
-  if(table->numelements > table->capacity) {
+  if (node->key==0) {
+    node->ptr=val;
+    node->key=key;
+    return;
+  }
+
+  if(ne > table->capacity) {
     //Resize
-    newsize = table->size << 1;
+    unsigned int newsize = table->size << 1;
     chashResize(table,newsize);
+    node = &table->table[(key & table->mask)>>1];
+    if (node->key==0) {
+      node->ptr=val;
+      node->key=key;
+      return;
+    }
   }
-  index=(key &table->mask)>>1;
-  while(1) {
-    node = &table->table[index];
-    if (node->ptr==NULL) {
+
+
+  for(i=1;1;i++) {
+    node = &table->table[((key+i*331) & table->mask)>>1];
+    if (node->key==0) {
       node->ptr=val;
       node->key=key;
       return;
     }
-    index++;
-    if (index==table->size)
-      index=0;
   }
 }
 
 // Search for an address for a given oid
 INLINE void * chashSearch(chashtable_t *table, unsigned int key) {
   //REMOVE HASH FUNCTION CALL TO MAKE SURE IT IS INLINED HERE
-  unsigned int tmp=(key &table->mask)>>1;
-  struct chashentry *node;
-  unsigned int ckey;
-  while(1) {
-    node = &table->table[tmp];
+  struct chashentry *node=&table->table[(key & table->mask)>>1];
+  unsigned int i,ckey;
+
+  if (node->key==key)
+    return node->ptr;
+  if (node->key==0)
+    return NULL;
+
+  for(i=1;1;i++) {
+    node = &table->table[((key+i*331) & table->mask)>>1];
     ckey=node->key;
     if (ckey==key)
       return node->ptr;
     if (ckey==0)
       return NULL;
-    tmp++;
-    if (tmp==table->size)
-      tmp=0;
   }
 }
 
@@ -91,29 +103,30 @@ void chashResize(chashtable_t *table, unsigned int newsize) {
     printf("Calloc error %s %d\n", __FILE__, __LINE__);
     return;
   }
-
   table->table = node;          //Update the global hashtable upon resize()
   table->size = newsize;
-  mask=table->mask = (newsize << 1)-1;
-  table->numelements = 0;
+  table->capacity=table->loadfactor*table->size;
+  mask=(table->mask = (newsize << 1)-1);
 
   for(i = 0; i < oldsize; i++) {                        //Outer loop for each bin in hash table
     curr=&ptr[i];
     key=curr->key;
     if (key != 0) {
-      bin=(key&mask)>>1;
-      while(1) {
-       newnode= &table->table[bin];
+      newnode= &table->table[(key&mask)>>1];
+      if (newnode->key==0) {
+       newnode->key=key;
+       newnode->ptr=curr->ptr;
+       continue;
+      }
+
+      for(bin=1;1;bin++) {
+       newnode = &table->table[((key+bin*331) & mask)>>1];
        if (newnode->key==0) {
          newnode->key=key;
          newnode->ptr=curr->ptr;
          break;
        }
-       bin++;
-       if (bin==newsize)
-         bin=0;
       }
-
     }
   }
   free(ptr);            //Free the memory of the old hash table
index cafa0a726346a13f57a2297a8aef13c72b5bee3e..70ae96173104b547289e0a0dd43637e78dbb0139 100644 (file)
@@ -23,7 +23,7 @@ typedef struct chashtable {
 
 /* Prototypes for hash*/
 chashtable_t *chashCreate(unsigned int size, float loadfactor);
-static unsigned int chashFunction(chashtable_t *table, unsigned int key);
+static unsigned int chashFunction(chashtable_t *table, unsigned int key, unsigned int i);
 void chashInsert(chashtable_t *table, unsigned int key, void *val);
 void *chashSearch(chashtable_t *table, unsigned int key); //returns val, NULL if not found
 void chashResize(chashtable_t *table, unsigned int newsize);
index 10360a606cc71a87bb4ce5f8f0e37b2c0d2a7653..27e61f7ebe1d5a55584534b6417b428aad8eef81 100644 (file)
@@ -334,6 +334,24 @@ transrecord_t *transStart() {
   return tmp;
 }
 
+// Search for an address for a given oid                                                                               
+/*#define INLINE    inline __attribute__((always_inline))
+
+INLINE void * chashSearchI(chashtable_t *table, unsigned int key) {
+  //REMOVE HASH FUNCTION CALL TO MAKE SURE IT IS INLINED HERE                                                          
+  chashlistnode_t *node = &table->table[(key & table->mask)>>1];
+
+  do {
+    if(node->key == key) {
+      return node->val;
+    }
+    node = node->next;
+  } while(node != NULL);
+
+  return NULL;
+  }*/
+
+
 /* This function finds the location of the objects involved in a transaction
  * and returns the pointer to the object if found in a remote location */
 objheader_t *transRead(transrecord_t *record, unsigned int oid) {
@@ -342,22 +360,42 @@ objheader_t *transRead(transrecord_t *record, unsigned int oid) {
   objheader_t *objcopy;
   int size;
   void *buf;
+  chashlistnode_t *node;
+  chashtable_t *table=record->lookupTable;
 
   if(oid == 0) {
     return NULL;
   }
+  
+  node= &table->table[(oid & table->mask)>>1];
+  do {
+    if(node->key == oid) {
+#ifdef TRANSSTATS
+    nchashSearch++;
+#endif
+#ifdef COMPILER
+    return &((objheader_t*)node->val)[1];
+#else
+    return node->val;
+#endif
+    }
+    node = node->next;
+  } while(node != NULL);
+  
 
-  if((objheader = chashSearch(record->lookupTable, oid)) != NULL) {
+  /*  
+  if((objheader = chashSearchI(record->lookupTable, oid)) != NULL) {
 #ifdef TRANSSTATS
     nchashSearch++;
 #endif
-    /* Search local transaction cache */
 #ifdef COMPILER
     return &objheader[1];
 #else
     return objheader;
 #endif
-  } else if ((objheader = (objheader_t *) mhashSearch(oid)) != NULL) {
+  } else 
+  */
+  if ((objheader = (objheader_t *) mhashSearch(oid)) != NULL) {
 #ifdef TRANSSTATS
     nmhashSearch++;
 #endif
@@ -434,6 +472,7 @@ objheader_t *transCreateObj(transrecord_t *record, unsigned int size) {
 #endif
 }
 
+#if 1
 /* This function creates machine piles based on all machines involved in a
  * transaction commit request */
 plistnode_t *createPiles(transrecord_t *record) {
@@ -452,11 +491,7 @@ plistnode_t *createPiles(transrecord_t *record) {
       //if the first bin in hash table is empty
       if(curr->key == 0)
        break;
-
-      if ((headeraddr = (objheader_t *) chashSearch(record->lookupTable, curr->key)) == NULL) {
-       printf("Error: No such oid %s, %d\n", __FILE__, __LINE__);
-       return NULL;
-      }
+      headeraddr=(objheader_t *) curr->val;
 
       //Get machine location for object id (and whether local or not)
       if (STATUS(headeraddr) & NEW || (mhashSearch(curr->key) != NULL)) {
@@ -473,6 +508,40 @@ plistnode_t *createPiles(transrecord_t *record) {
   }
   return pile;
 }
+#else
+/* This function creates machine piles based on all machines involved in a
+ * transaction commit request */
+plistnode_t *createPiles(transrecord_t *record) {
+  int i;
+  plistnode_t *pile = NULL;
+  unsigned int machinenum;
+  objheader_t *headeraddr;
+  struct chashentry * ptr = record->lookupTable->table;
+  /* Represents number of bins in the chash table */
+  unsigned int size = record->lookupTable->size;
+
+  for(i = 0; i < size ; i++) {
+    struct chashentry * curr = & ptr[i];
+    /* Inner loop to traverse the linked list of the cache lookupTable */
+    //if the first bin in hash table is empty
+    if(curr->key == 0)
+      continue;
+    headeraddr=(objheader_t *) curr->ptr;
+
+    //Get machine location for object id (and whether local or not)
+    if (STATUS(headeraddr) & NEW || (mhashSearch(curr->key) != NULL)) {
+      machinenum = myIpAddr;
+    } else if ((machinenum = lhashSearch(curr->key)) == 0) {
+      printf("Error: No such machine %s, %d\n", __FILE__, __LINE__);
+      return NULL;
+    }
+
+    //Make machine groups
+    pile = pInsert(pile, headeraddr, machinenum, record->lookupTable->numelements);
+  }
+  return pile;
+}
+#endif
 
 /* This function initiates the transaction commit process
  * Spawns threads for each of the new connections with Participants