From de2479707660ec81b274cff33a2068b7366a0265 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Wed, 13 May 2009 08:05:01 +0000 Subject: [PATCH] make atomic work in normal java mode...it just uses coarse locks --- Robust/src/Benchmarks/SingleTM/KMeans/Normal.java | 7 ++++--- Robust/src/Benchmarks/SingleTM/KMeans/makefile | 2 +- Robust/src/Benchmarks/SingleTM/LeeRouting/makefile | 2 +- Robust/src/IR/Flat/BuildCode.java | 13 +++++++++++-- Robust/src/Runtime/thread.c | 11 ++++++++--- Robust/src/Runtime/thread.h | 2 ++ 6 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Robust/src/Benchmarks/SingleTM/KMeans/Normal.java b/Robust/src/Benchmarks/SingleTM/KMeans/Normal.java index c845fcfe..93f3bf74 100644 --- a/Robust/src/Benchmarks/SingleTM/KMeans/Normal.java +++ b/Robust/src/Benchmarks/SingleTM/KMeans/Normal.java @@ -114,6 +114,7 @@ public class Normal { //System.out.println("myId= " + myId + " start= " + start + " npoints= " + npoints); while (start < npoints) { stop = (((start + CHUNK) < npoints) ? (start + CHUNK) : npoints); + for (int i = start; i < stop; i++) { index = Common.common_findNearestPoint(feature[i], nfeatures, @@ -132,17 +133,17 @@ public class Normal { membership[i] = index; /* Update new cluster centers : sum of objects located within */ - atomic { + atomic { new_centers_len[index] = new_centers_len[index] + 1; for (int j = 0; j < nfeatures; j++) { new_centers[index][j] = new_centers[index][j] + feature[i][j]; } - } + } } /* Update task queue */ if (start + CHUNK < npoints) { - atomic { + atomic { start = (int) args.global_i; args.global_i = start + CHUNK; } diff --git a/Robust/src/Benchmarks/SingleTM/KMeans/makefile b/Robust/src/Benchmarks/SingleTM/KMeans/makefile index 5c244f06..0c035dd0 100644 --- a/Robust/src/Benchmarks/SingleTM/KMeans/makefile +++ b/Robust/src/Benchmarks/SingleTM/KMeans/makefile @@ -6,7 +6,7 @@ SRC=${MAINCLASS}.java \ Common.java \ GlobalArgs.java \ ../../../ClassLibrary/JavaSTM/Barrier.java -FLAGS=-mainclass ${MAINCLASS} -singleTM -optimize -debug -dcopts -transstats -joptimize +FLAGS=-mainclass ${MAINCLASS} -singleTM -optimize -debug -dcopts -joptimize -fastmemcpy -garbagestats FLAGS2=-mainclass ${MAINCLASS} -optimize -debug -joptimize -thread diff --git a/Robust/src/Benchmarks/SingleTM/LeeRouting/makefile b/Robust/src/Benchmarks/SingleTM/LeeRouting/makefile index 62fd7507..4807004e 100644 --- a/Robust/src/Benchmarks/SingleTM/LeeRouting/makefile +++ b/Robust/src/Benchmarks/SingleTM/LeeRouting/makefile @@ -5,7 +5,7 @@ SRC=${MAINCLASS}.java \ GridCell.java \ LeeThread.java \ WorkQueue.java -FLAGS=-mainclass ${MAINCLASS} -joptimize -debug -singleTM -optimize -dcopts -transstats -abcclose -stmdebug -stmstats +FLAGS=-mainclass ${MAINCLASS} -joptimize -debug -singleTM -optimize -dcopts -transstats -abcclose -stmstats default: ../../../buildscript ${FLAGS} -o ${MAINCLASS} ${SRC} diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 3d8baea0..7d6f8b85 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -1970,7 +1970,12 @@ public class BuildCode { public void generateFlatAtomicEnterNode(FlatMethod fm, LocalityBinding lb, FlatAtomicEnterNode faen, PrintWriter output) { /* Check to see if we need to generate code for this atomic */ - if (locality==null||locality.getAtomic(lb).get(faen.getPrev(0)).intValue()>0) + if (locality==null) { + output.println("pthread_mutex_lock(&atomiclock);"); + return; + } + + if (locality.getAtomic(lb).get(faen.getPrev(0)).intValue()>0) return; /* Backup the temps. */ for(Iterator tmpit=locality.getTemps(lb).get(faen).iterator(); tmpit.hasNext();) { @@ -2013,7 +2018,11 @@ public class BuildCode { public void generateFlatAtomicExitNode(FlatMethod fm, LocalityBinding lb, FlatAtomicExitNode faen, PrintWriter output) { /* Check to see if we need to generate code for this atomic */ - if (locality==null||locality.getAtomic(lb).get(faen).intValue()>0) + if (locality==null) { + output.println("pthread_mutex_unlock(&atomiclock);"); + return; + } + if (locality.getAtomic(lb).get(faen).intValue()>0) return; //store the revert list before we lose the transaction object String revertptr=null; diff --git a/Robust/src/Runtime/thread.c b/Robust/src/Runtime/thread.c index ec8ee1d8..ebb24df2 100644 --- a/Robust/src/Runtime/thread.c +++ b/Robust/src/Runtime/thread.c @@ -26,6 +26,8 @@ pthread_cond_t gccond; pthread_mutex_t objlock; pthread_cond_t objcond; +pthread_mutex_t atomiclock; + pthread_mutex_t joinlock; pthread_cond_t joincond; pthread_key_t threadlocks; @@ -65,7 +67,7 @@ void threadexit() { #endif pthread_mutex_lock(&gclistlock); #ifdef THREADS - pthread_setspecific(threadlocks, litem->locklist); + pthread_setspecific(threadlocks, litem.locklist); #endif #ifndef MAC if (litem.prev==NULL) { @@ -123,6 +125,9 @@ void threadhandler(int sig, siginfo_t *info, void *uap) { void initializethreads() { struct sigaction sig; threadcount=1; +#ifdef THREADS + pthread_mutex_init(&atomiclock, NULL); +#endif pthread_mutex_init(&gclock, NULL); pthread_mutex_init(&gclistlock, NULL); pthread_cond_init(&gccond, NULL); @@ -232,7 +237,7 @@ void initthread(struct ___Thread___ * ___this___) { pthread_mutex_lock(&gclistlock); #ifdef THREADS - pthread_setspecific(threadlocks, litem->locklist); + pthread_setspecific(threadlocks, litem.locklist); #endif if (litem.prev==NULL) { list=litem.next; @@ -402,7 +407,7 @@ void initDSMthread(int *ptr) { pthread_mutex_lock(&gclistlock); #ifdef THREADS - pthread_setspecific(threadlocks, litem->locklist); + pthread_setspecific(threadlocks, litem.locklist); #endif if (litem.prev==NULL) { list=litem.next; diff --git a/Robust/src/Runtime/thread.h b/Robust/src/Runtime/thread.h index 26dd0e1c..d2f80dfa 100644 --- a/Robust/src/Runtime/thread.h +++ b/Robust/src/Runtime/thread.h @@ -10,6 +10,8 @@ extern pthread_cond_t gccond; extern pthread_mutex_t objlock; extern pthread_cond_t objcond; extern pthread_key_t threadlocks; +extern pthread_mutex_t atomiclock; + #if defined(THREADS)||defined(STM) void initthread(struct ___Thread___ * ___this___); #endif -- 2.34.1