[parsec-users] Serial implementation of Canneal

Mark Roth mroth at sfu.ca
Tue Jan 24 22:42:28 EST 2012


Here is the patch that removes atomic pointers from the serial
implementation of Canneal as they are not required. This improves the
serial performance by 30-40%.

- Mark

<<<<<< Begin Patch >>>>>>>

>From 9fefc57a8533c1a4abee0767862a223fd99266d5 Mon Sep 17 00:00:00 2001
From: Mark Roth <mr.mark.roth at gmail.com>
Date: Tue, 24 Jan 2012 18:22:09 -0800
Subject: [PATCH] removed atomic ptr from serial version

---
 annealer_thread.cpp |    5 +++++
 netlist.cpp         |   19 +++++++++++++++++++
 netlist_elem.cpp    |   16 ++++++++++++++++
 netlist_elem.h      |    8 ++++++++
 4 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/annealer_thread.cpp b/annealer_thread.cpp
index dfbb79c..dae2134 100644
--- a/annealer_thread.cpp
+++ b/annealer_thread.cpp
@@ -117,8 +117,13 @@ annealer_thread::move_decision_t
annealer_thread::accept_move(routing_cost_t del
 //*****************************************************************************************
 routing_cost_t
annealer_thread::calculate_delta_routing_cost(netlist_elem* a,
netlist_elem* b)
 {
+#ifdef ENABLE_THREADS
 	location_t* a_loc = a->present_loc.Get();
 	location_t* b_loc = b->present_loc.Get();
+#else
+	location_t* a_loc = a->present_loc;
+	location_t* b_loc = b->present_loc;
+#endif
 	
 	routing_cost_t delta_cost = a->swap_cost(a_loc, b_loc);
 	delta_cost += b->swap_cost(b_loc, a_loc);
diff --git a/netlist.cpp b/netlist.cpp
index bd1d77c..6cc002d 100644
--- a/netlist.cpp
+++ b/netlist.cpp
@@ -55,7 +55,11 @@ routing_cost_t netlist::total_routing_cost()
 		 iter != _elem_names.end();
 		 ++iter){
 		netlist_elem* elem = iter->second;
+#ifdef ENABLE_THREADS
 		rval += elem->routing_cost_given_loc(*(elem->present_loc.Get()));
+#else
+		rval += elem->routing_cost_given_loc(*(elem->present_loc));
+#endif
 	}
 	return rval / 2; //since routing_cost calculates both input and
output routing, we have double counted
 }
@@ -81,7 +85,13 @@ void netlist::shuffle(Rng* rng)
 void netlist::swap_locations(netlist_elem* elem_a, netlist_elem* elem_b)
 {
 	//and swap the locations stored in the actual netlist_elem
+#ifdef ENABLE_THREADS
 	elem_a->present_loc.Swap(elem_b->present_loc);
+#else
+	location_t* tmp = elem_a->present_loc;
+	elem_a->present_loc = elem_b->present_loc;
+	elem_b->present_loc = tmp;
+#endif
 }


@@ -179,12 +189,17 @@ netlist::netlist(const std::string& filename)
 			location_t* loc = &_locations.at(x).at(y);
 			loc->x = x;
 			loc->y = y;
+#ifdef ENABLE_THREADS
 			_elements.at(i_elem).present_loc.Set(loc);
+#else
+			_elements.at(i_elem).present_loc = loc;
+#endif
 			i_elem++;
 		}//for (int y = 0; y < _max_y; y++)
 	}//for (int x = 0; x < _max_x; x++)
 	cout << "locs assigned" << endl;

+
 	int i=0;
 	while (!fin.eof()){
 		i++;
@@ -249,6 +264,10 @@ void netlist::print_locations(const std::string& filename)
 		 iter != _elem_names.end();
 		 ++iter){
 		netlist_elem* elem = iter->second;
+#ifdef ENABLE_THREADS
 		fout << elem->item_name << "\t" << elem->present_loc.Get()->x <<
"\t" << elem->present_loc.Get()->y << std::endl;
+#else
+		fout << elem->item_name << "\t" << elem->present_loc->x << "\t" <<
elem->present_loc->y << std::endl;
+#endif
 	}
 }
diff --git a/netlist_elem.cpp b/netlist_elem.cpp
index 5ab4758..7bd2790 100644
--- a/netlist_elem.cpp
+++ b/netlist_elem.cpp
@@ -54,13 +54,21 @@ routing_cost_t
netlist_elem::routing_cost_given_loc(location_t loc)
 	routing_cost_t fanout_cost = 0;
 	
 	for (int i = 0; i< fanin.size(); ++i){
+#ifdef ENABLE_THREADS
 		location_t* fanin_loc = fanin[i]->present_loc.Get();
+#else
+		location_t* fanin_loc = fanin[i]->present_loc;
+#endif
 		fanin_cost += fabs(loc.x - fanin_loc->x);
 		fanin_cost += fabs(loc.y - fanin_loc->y);
 	}

 	for (int i = 0; i< fanout.size(); ++i){
+#ifdef ENABLE_THREADS
 		location_t* fanout_loc = fanout[i]->present_loc.Get();
+#else
+		location_t* fanout_loc = fanout[i]->present_loc;
+#endif
 		fanout_cost += fabs(loc.x - fanout_loc->x);
 		fanout_cost += fabs(loc.y - fanout_loc->y);
 	}
@@ -78,7 +86,11 @@ routing_cost_t netlist_elem::swap_cost(location_t*
old_loc, location_t* new_loc)
 	routing_cost_t yes_swap = 0;
 	
 	for (int i = 0; i< fanin.size(); ++i){
+#ifdef ENABLE_THREADS
 		location_t* fanin_loc = fanin[i]->present_loc.Get();
+#else
+		location_t* fanin_loc = fanin[i]->present_loc;
+#endif
 		no_swap += fabs(old_loc->x - fanin_loc->x);
 		no_swap += fabs(old_loc->y - fanin_loc->y);
 		
@@ -87,7 +99,11 @@ routing_cost_t netlist_elem::swap_cost(location_t*
old_loc, location_t* new_loc)
 	}
 	
 	for (int i = 0; i< fanout.size(); ++i){
+#ifdef ENABLE_THREADS
 		location_t* fanout_loc = fanout[i]->present_loc.Get();
+#else
+		location_t* fanout_loc = fanout[i]->present_loc;
+#endif
 		no_swap += fabs(old_loc->x - fanout_loc->x);
 		no_swap += fabs(old_loc->y - fanout_loc->y);
 		
diff --git a/netlist_elem.h b/netlist_elem.h
index a79d4b6..dba4215 100644
--- a/netlist_elem.h
+++ b/netlist_elem.h
@@ -33,11 +33,15 @@
 #include <string>
 #include <vector>

+#ifndef ENABLE_THREADS
 #include "AtomicPtr.h"
+#endif
 #include "location_t.h"
 #include "annealer_types.h"

+#ifdef ENABLE_THREADS
 using threads::AtomicPtr;
+#endif

 class netlist_elem{
 public:	
@@ -49,7 +53,11 @@ public:
 	std::string item_name;
 	std::vector<netlist_elem*> fanin;
 	std::vector<netlist_elem*> fanout;
+#ifdef ENABLE_THREADS
 	AtomicPtr<location_t> present_loc;
+#else
+	location_t* present_loc;
+#endif
 	
 protected:
 };
-- 
1.7.5.4


More information about the parsec-users mailing list