Object get(Object key) {
int hashcode=key.hashCode();
int index1=hash1(hashcode, table.length);
- /****** Add Manual Prefetch *****/
- //table[index1].array
- Object obj = table;
- short[] offsets = new short[4];
- offsets[0] = (short) index1;
- offsets[1] = (short) 0;
- offsets[2] = getoffset {DistributedHashEntry, array};
- offsets[3] = (short) 0;
- System.rangePrefetch(obj,offsets);
- /********************************/
-
+
DistributedHashEntry dhe=table[index1];
if (dhe==null)
return null;
int index2=hash2(hashcode, table.length, dhe.array.length);
- /****** Add Manual Prefetch *****/
- //dhe.array[index2].next(5).key
- Object obj1 = dhe;
- short[] offsets1 = new short[8];
- offsets1[0] = getoffset {DistributedHashEntry, array};
- offsets1[1] = (short) 0;
- offsets1[2] = (short) index2;
- offsets1[3] = (short) 0;
- offsets1[4] = getoffset {DHashEntry, next};
- offsets1[5] = (short) 5;
- offsets1[6] = getoffset {DHashEntry, key};
- offsets1[7] = (short) 0;
- System.rangePrefetch(obj1, offsets1);
- /********************************/
-
+
DHashEntry ptr=dhe.array[index2];
while(ptr!=null) {
MAINCLASS=LookUpService
SRC1=${MAINCLASS}.java \
DistributedHashMap.java
-FLAGS1=-dsm -dsmcaching -rangeprefetch -optimize -mainclass ${MAINCLASS} -trueprob 0.95
FLAGS2=-dsm -dsmcaching -prefetch -optimize -excprefetch String.hashCode -excprefetch DistributedHashMap.resize -excprefetch String.equals -excprefetch LookUpService.main -mainclass ${MAINCLASS} -trueprob 0.95
FLAGS3=-dsm -optimize -mainclass ${MAINCLASS}
FLAGS4=-dsm -dsmcaching -optimize -mainclass ${MAINCLASS}
default:
../../../../buildscript ${FLAGS3} -o ${MAINCLASS}NPNC ${SRC1}
../../../../buildscript ${FLAGS2} -o ${MAINCLASS}N ${SRC1}
- ../../../../buildscript ${FLAGS1} -o ${MAINCLASS}RangeN ${SRC1}
../../../../buildscript ${FLAGS4} -o ${MAINCLASS}NPC ${SRC1}
clean:
rm -rf tmpbuilddirectory
**/
private int nLookUp;
+
+ private int seed;
+
public LookUpClient() {
}
- public LookUpClient(int numtrans, int nobjs, int rdprob, int nLookUp) {
+ public LookUpClient(int numtrans, int nobjs, int rdprob, int nLookUp, int seed) {
this.numtrans = numtrans;
this.nobjs = nobjs;
this.rdprob = rdprob;
this.nLookUp = nLookUp;
+ this.seed = seed;
}
public static void main(String[] args) {
LookUpClient.parseCmdLine(args, lc);
Socket sock = new Socket("dc-1.calit2.uci.edu",9001);
- Random rand = new Random(0);
-
+ Random rand = new Random(lc.seed);
+ SocketInputStream sin = new SocketInputStream(sock);
for (int i = 0; i < lc.numtrans; i++) {
for (int j = 0; j < lc.nLookUp; j++) {
} else {
operation = 2;//update hashmap
}
- lc.doLookUp(operation, sock, rwkey);
+ lc.doLookUp(operation, sock, rwkey, sin);
}
}
/** Special character to terminate computation **/
String op = new String("t");
sock.write(op.getBytes());
+ sock.close();
}
/**
* Call to do a read/ write on socket
**/
- public void doLookUp(int operation, Socket sock, int key){
+ public void doLookUp(int operation, Socket sock, int key, SocketInputStream sin){
String op;
if (operation == 1) {
sock.write(fillBytes(operation, key));
byte b[] = new byte[4];
- int numbytes = sock.read(b);
+ String str1 = readFromSock(sin, 4);
} else {
sock.write(fillBytes(operation, key));
}
int offset = (3-(i-1)) * 8;
b[i] = (byte) ((key >> offset) & 0xFF);
}
+ //
+ // Debug
+ // System.println("Sending b[0]= "+ (char) b[0]);
+ //
return b;
}
if(i < args.length) {
lc.nLookUp = new Integer(args[i++]).intValue();
}
+ } else if(arg.equals("-seed")) {
+ if(i < args.length) {
+ lc.seed = new Integer(args[i++]).intValue();
+ }
} else if(arg.equals("-h")) {
lc.usage();
}
}
- if(lc.nobjs == 0 || lc.numtrans == 0)
+ if(lc.nobjs == 0 || lc.numtrans == 0 || lc.nLookUp == 0)
lc.usage();
}
* The usage routine which describes the program options.
**/
public void usage() {
- System.printString("usage: ./Client.bin -nObjs <objects in hashmap> -nTrans <number of transactions> -probRead <read probability> -nLookUp <number of lookups>\n");
+ System.printString("usage: ./Client.bin -nObjs <objects in hashmap> -nTrans <number of transactions> -probRead <read probability> -nLookUp <number of lookups> -seed <seed value for Random variable>\n");
System.printString(" -nObjs the number of objects to be inserted into distributed hashmap\n");
System.printString(" -nTrans the number of transactions to run\n");
System.printString(" -probRead the probability of read given a transaction\n");
System.printString(" -nLookUp the number of lookups per transaction\n");
+ System.printString(" -seed the seed value for Random\n");
System.printString(" -h help with usage\n");
}
+
+ /**
+ ** Repeated read until you get all bytes
+ **/
+ String readFromSock(SocketInputStream si, int maxBytes) {
+ byte []b=new byte[maxBytes];
+ int numbytes;
+ if ((numbytes = si.readAll(b))<0)
+ System.out.println("Error\n");
+ //
+ // Debug
+ // System.println("numbytes received= " + numbytes);
+ //
+ return new String(b);
+ }
}
for(int i=0; i<nthreads; i++) {
lus[i].join();
}
+
+ ss.close();
System.println("Finished");
+ System.exit(0);
}
/**
public class LookUpServerThread extends Thread {
HashMap hmap;
Socket sock;
+ SocketInputStream sin;
public LookUpServerThread(Socket s, HashMap h) {
hmap = h;
sock = s;
+ this.sin = new SocketInputStream(sock);
}
public void run() {
- Random r=new Random(0);
+ Random r=new Random(0);
+ byte b[] = new byte[1]; //1 byte to decide if terminate or continue
+ byte b1[] = new byte[4];//4 bytes to get the Key to search
while(true) {
- byte b[] = new byte[1];
- int numbytes = sock.read(b);
- String str1 = (new String(b)).subString(0, numbytes);
+ String readStr = readFromSock(1);
+ String str1 = readStr.subString(0, 1);
/* terminate if opcode sent is "t" */
if(str1.equalsIgnoreCase("t")) {
sock.close();
break;
} else {
- byte b1[] = new byte[4];
- numbytes = sock.read(b1);
+ readStr = readFromSock(4);
+ b1 = readStr.getBytes();
int val = getKey(b1);
Integer keyitem = new Integer(val);
/* read from hashmap if opcode sent is "r" */
//Write object to socket for client
sock.write(tmpval.intToByteArray());
} else {
- /* update hashmap if opcode sent is "w" */
- doUpdate(r, this, keyitem);
+ /* update hashmap if opcode sent is "w" */
+ doUpdate(r, this, keyitem);
}
}
}
val = ((b[0] & 0xFF) << 24) + ((b[1] & 0xFF) << 16) + ((b[2] & 0xFF) << 8) + (b[3] & 0xFF);
return val;
}
+
+ /**
+ ** Repeated read until you get all bytes
+ **/
+ String readFromSock(int maxBytes) {
+ byte []b=new byte[maxBytes];
+ int numbytes;
+ if ((numbytes = sin.readAll(b))<0)
+ System.out.println("Error\n");
+ //
+ // Debug
+ // System.println("numbytes received= " + numbytes +" b[0]= " + (char) b[0]);
+ //
+ return new String(b);
+ }
}
SRC1=${MAINCLASS1}.java \
LookUpServerThread.java
SRC2=${MAINCLASS2}.java
-FLAGS= -thread -optimize -mainclass ${MAINCLASS1}
-FLAGS1= -thread -optimize -mainclass ${MAINCLASS2}
+FLAGS= -thread -nooptimize -debug -mainclass ${MAINCLASS1}
+FLAGS1= -thread -nooptimize -debug -mainclass ${MAINCLASS2}
default :
../../../../buildscript ${FLAGS} -o Server ${SRC1}
FLAGS1=-dsm -optimize -mainclass ${MAINCLASS}
FLAGS2=-dsm -dsmcaching -optimize -mainclass ${MAINCLASS}
-FLAGS3=-dsm -dsmcaching -prefetch -optimize -mainclass ${MAINCLASS} -trueprob 0.90
+FLAGS3=-dsm -dsmcaching -prefetch -optimize -mainclass ${MAINCLASS} -excprefetch BarrierServer.updateAge -excprefetch RainForest.main -excprefetch GameMap.hasRock -excprefetch GameMap.hasTree -trueprob 0.90
default:
cpp ${MAINCLASS}.java > tmp1${MAINCLASS}.java
./extractLines
../../../../buildscript ${FLAGS1} -o ${MAINCLASS}NPNC ${SRC}
- ../../../../buildscript ${FLAGS2} -o ${MAINCLASS}NPC ${SRC1}
+ ../../../../buildscript ${FLAGS2} -o ${MAINCLASS}NPC ${SRC}
../../../../buildscript ${FLAGS3} -o ${MAINCLASS}N ${SRC}
clean:
public class RainForestClient {
+ /**
+ ** The random seed
+ **/
+ int seed;
+
+ public RainForestClient(int seed) {
+ this.seed = seed;
+ }
+
public RainForestClient() {
}
public static void main(String[] args) {
- int seed;
- if(args.length>0) {
- seed = Integer.parseInt(args[0]);
- }
-
- Random rand = new Random(seed);
RainForestClient rfc = new RainForestClient();
+ RainForestClient.parseCmdLine(args, rfc);
+
+ Random rand = new Random(rfc.seed);
Socket sock = new Socket("dc-1.calit2.uci.edu",9002);
SocketInputStream si=new SocketInputStream(sock);
System.out.println("Error\n");
return new String(b);
}
+
+ /**
+ * Parse the command line options.
+ **/
+ public static void parseCmdLine(String args[], RainForestClient rfc) {
+ int i = 0;
+ String arg;
+ while(i < args.length && args[i].startsWith("-")) {
+ arg = args[i++];
+ //check options
+ if(arg.equals("-seed")) {
+ if(i < args.length) {
+ rfc.seed = new Integer(args[i++]).intValue();
+ }
+ } else if(arg.equals("-h")) {
+ rfc.usage();
+ }
+ }
+
+ if(rfc.seed <= 0)
+ rfc.usage();
+ }
+
+ /**
+ * The usage routine which describes the program options.
+ **/
+ public void usage() {
+ System.printString("usage: ./Client.bin -seed <seed value for Random variable>\n");
+ System.printString(" -seed the seed value for Random\n");
+ System.printString(" -h help with usage\n");
+ }
}
#define COLUMN 100 /* rows of in the map */
public class RainForestServerExample {
- private int numThreads;
+ /**
+ ** Number of threads
+ **/
+ int numThreads;
public RainForestServerExample() {
}
public static int main(String args[]) {
- int numThreads;
- if(args.length>0) {
- numThreads = Integer.parseInt(args[0]);
- }
+ RainForestServerExample rfe = new RainForestServerExample();
+ RainForestServerExample.parseCmdLine(args, rfe);
/**
* Create shared Map
}
ServerSocket ss = new ServerSocket(9002);
- acceptConnection(ss, world, numThreads);
+ acceptConnection(ss, world, rfe.numThreads);
}
public static void acceptConnection(ServerSocket ss, GameMap[][] world, int numThreads) {
AStarPathFinder.java \
BarrierNonDSM.java
-FLAGS1= -thread -nooptimize -debug -mainclass ${MAINCLASS1}
-FLAGS2= -thread -nooptimize -debug -mainclass ${MAINCLASS2}
+FLAGS1= -thread -optimize -mainclass ${MAINCLASS1}
+FLAGS2= -thread -optimize -mainclass ${MAINCLASS2}
default:
cpp RainForestServerExample.java > tmp1RainForestServerExample.java
--- /dev/null
+LookUpService:-nObjs 160:-nObjs 160 -nTrans 1000 -probRead 96 -nLookUp 10:LookUpServerExample:LookUpClient
+RainForest::::
--- /dev/null
+#!/bin/sh
+./runjava.sh 6
done
}
-exec < bm_jargs.txt
+exec < bm_args.txt
while read line
do
BM_NAME=`echo $line | cut -f1 -d":"`