Commit f05e1008 authored by Robert Ricci's avatar Robert Ricci

'port' assign to compile under gcc 3 (specifically tested with 3.3.1).

This mostly required messing with the STL #includes.

Still builds under gcc 2.95, and won't be built with 3.3 by default
until I've spent more time testing it.

One reason for doing this is that gcc 3.3 seems to generate faster
code from templated functions. Tests so far show that the
gcc3-compiled binary shaves 15-30% off of assign's runtime.

The other reason for doing this is forward-looking. When we end up
getting boss running on FreeBSD 5 or a recent Linux distro, the
compiler is likely to be from the gcc 3 branch.
parent ec0d1650
......@@ -9,6 +9,13 @@ MAKEFILE_IN = @srcdir@/GNUmakefile.in
include $(OBJDIR)/Makeconf
#
# Uncomment these to build with gcc3.3
#
#CC=gcc33
#CPP=cpp33
#CXX=g++33
all: assign
include $(TESTBED_SRCDIR)/GNUmakerules
......
......@@ -6,6 +6,13 @@
#include "anneal.h"
#include "virtual.h"
#include "maps.h"
#include "common.h"
#include "score.h"
#include "solution.h"
#include "vclass.h"
/*
* Internal variables
*/
......@@ -51,7 +58,7 @@ inline int accept(double change, double temperature)
} else {
p = expf(change/temperature) * 1000;
}
r = std::random() % 1000;
r = random() % 1000;
if (r < p) {
return 1;
}
......@@ -175,8 +182,8 @@ tb_pnode *find_pnode_connected(vvertex vv, tb_vnode *vn) {
visit_order[i] = *vedge_it;
}
for (int i = 0; i < visit_order.size(); i++) {
int i1 = std::random() % visit_order.size();
int i2 = std::random() % visit_order.size();
int i1 = random() % visit_order.size();
int i2 = random() % visit_order.size();
vedge tmp = visit_order[i1];
visit_order[i1] = visit_order[i2];
visit_order[i2] = tmp;
......@@ -234,8 +241,8 @@ tb_pnode *find_pnode(tb_vnode *vn)
traversal_order[i] = i;
}
for (int i = 0; i < num_types; i++) {
int i1 = std::random() % num_types;
int i2 = std::random() % num_types;
int i1 = random() % num_types;
int i2 = random() % num_types;
int tmp = traversal_order[i1];
traversal_order[i1] = traversal_order[i2];
traversal_order[i2] = tmp;
......@@ -444,7 +451,7 @@ void anneal(bool scoring_selftest, double scale_neighborhood,
absassignment[*vit] = vn->assignment;
abstypes[*vit] = vn->type;
} else {
unassigned_nodes.push(vvertex_int_pair(*vit,std::random()));
unassigned_nodes.push(vvertex_int_pair(*vit,random()));
}
}
......@@ -578,7 +585,7 @@ void anneal(bool scoring_selftest, double scale_neighborhood,
assert(!get(vvertex_pmap,vv)->assigned);
unassigned_nodes.pop();
} else {
int start = std::random()%nnodes;
int start = random()%nnodes;
int choice = start;
while (get(vvertex_pmap,virtual_nodes[choice])->fixed) {
choice = (choice +1) % nnodes;
......@@ -619,7 +626,7 @@ void anneal(bool scoring_selftest, double scale_neighborhood,
// Actually find a pnode
tb_pnode *newpnode = NULL;
if ((use_connected_pnode_find != 0)
&& ((std::random() % 1000) < (use_connected_pnode_find * 1000))) {
&& ((random() % 1000) < (use_connected_pnode_find * 1000))) {
newpnode = find_pnode_connected(vv,vn);
}
if (newpnode == NULL) {
......@@ -634,7 +641,7 @@ void anneal(bool scoring_selftest, double scale_neighborhood,
if (newpnode == NULL) {
// We're not going to be re-assigning this one
#ifndef SMART_UNMAP
unassigned_nodes.push(vvertex_int_pair(vv,std::random()));
unassigned_nodes.push(vvertex_int_pair(vv,random()));
#endif
// need to free up nodes
#ifdef SMART_UNMAP
......@@ -649,7 +656,7 @@ void anneal(bool scoring_selftest, double scale_neighborhood,
pclass_vector *acceptable_types = tt.second;
// Find a node to kick out
bool foundnode = false;
int offi = std::random();
int offi = random();
int index;
for (int i = 0; i < size; i++) {
index = (i + offi) % size;
......@@ -668,14 +675,14 @@ void anneal(bool scoring_selftest, double scale_neighborhood,
assert((*acceptable_types)[index]->used_members[vn->type]->size());
tb_pclass::tb_pnodeset::iterator it =
(*acceptable_types)[index]->used_members[vn->type]->begin();
int j = std::random() %
int j = random() %
(*acceptable_types)[index]->used_members[vn->type]->size();
while (j > 0) {
it++;
j--;
}
tb_vnode_set::iterator it2 = (*it)->assigned_nodes.begin();
int k = std::random() % (*it)->assigned_nodes.size();
int k = random() % (*it)->assigned_nodes.size();
while (k > 0) {
it2++;
k--;
......@@ -686,13 +693,13 @@ void anneal(bool scoring_selftest, double scale_neighborhood,
newpnode = *it;
remove_node(toremove);
unassigned_nodes.push(vvertex_int_pair(toremove,
std::random()));
random()));
} else {
cerr << "Failed to find a replacement!" << endl;
}
#else
int start = std::random()%nnodes;
int start = random()%nnodes;
int toremove = start;
#ifdef SMART_UNMAP
......@@ -741,7 +748,7 @@ void anneal(bool scoring_selftest, double scale_neighborhood,
RDEBUG(cout << "removing: freeing up nodes" << endl;)
remove_node(virtual_nodes[toremove]);
unassigned_nodes.push(vvertex_int_pair(virtual_nodes[toremove],
std::random()));
random()));
}
continue;
#endif /* SMART_UNMAP */
......@@ -779,12 +786,12 @@ void anneal(bool scoring_selftest, double scale_neighborhood,
}
}
if (add_node(vv,newpos,false,false) != 0) {
unassigned_nodes.push(vvertex_int_pair(vv,std::random()));
unassigned_nodes.push(vvertex_int_pair(vv,random()));
continue;
}
} else {
#ifdef SMART_UNMAP
unassigned_nodes.push(vvertex_int_pair(vv,std::random()));
unassigned_nodes.push(vvertex_int_pair(vv,random()));
#endif
if (freednode) {
continue;
......
......@@ -16,21 +16,27 @@
#include <boost/graph/adjacency_list.hpp>
using namespace boost;
#include <rope>
#include <queue>
#include <iostream>
using namespace std;
/*
* We have to do these includes differently depending on which version of gcc
* we're compiling with
*/
#if __GNUC__ == 3 && __GNUC_MINOR__ > 0
#include <ext/hash_map>
#include <ext/slist>
using namespace __gnu_cxx;
#else
#include <hash_map>
#include <slist>
#endif
#include <math.h>
#include "common.h"
#include "delay.h"
#include "physical.h"
#include "virtual.h"
#include "vclass.h"
#include "maps.h"
#include "score.h"
#include "pclass.h"
#include "solution.h"
// Some defaults for #defines
#ifndef NO_REVERT
......@@ -76,4 +82,7 @@ tb_pnode *find_pnode(tb_vnode *vn);
void anneal(bool scoring_selftest, double scale_neighborhood,
double *initial_temperature, double use_connected_pnode_find);
typedef hash_map<crope,crope> name_name_map;
typedef slist<crope> name_slist;
#endif
......@@ -6,10 +6,6 @@
#include "port.h"
#include <hash_map>
#include <rope>
#include <queue>
#include <boost/config.hpp>
#include <boost/utility.hpp>
#include <boost/property_map.hpp>
......@@ -28,6 +24,7 @@
#include <sys/resource.h>
#include <signal.h>
#include <sys/signal.h>
#include <queue>
using namespace boost;
......@@ -775,7 +772,7 @@ int main(int argc,char **argv)
#endif
cout << "seed = " << seed << endl;
std::srandom(seed);
srandom(seed);
read_physical_topology(argv[0]);
calculate_switch_MST();
......
......@@ -7,8 +7,21 @@
#ifndef __COMON_H
#define __COMON_H
/*
* We have to do these includes differently depending on which version of gcc
* we're compiling with
*/
#if __GNUC__ == 3 && __GNUC_MINOR__ > 0
#include <ext/hash_map>
using namespace __gnu_cxx;
#else
#include <hash_map>
#endif
#include "config.h"
#include <boost/graph/adjacency_list.hpp>
/*
* Exit vaules from assign
*/
......@@ -170,9 +183,6 @@ namespace boost {
BOOST_INSTALL_PROPERTY(vertex,data);
}
typedef hash_map<crope,crope> name_name_map;
typedef slist<crope> name_slist;
/*
* Used to count the number of nodes in each ptype and vtype
*/
......@@ -197,4 +207,14 @@ template <class T> struct hashptr {
#define RDEBUG(a)
#endif
/*
* Needed for the transition from gcc 2.95 to 3.x - the new gcc puts some
* non-standard (ie. SGI) STL extensions in different place
*/
#if __GNUC__ == 3 && __GNUC_MINOR__ > 0
#define HASH_MAP <ext/hash_map>
#else
#define HASH_MAP
#endif
#endif
......@@ -7,8 +7,11 @@
#ifndef __DELAY_H
#define __DELAY_H
class tb_pnode;
// For DBL_MAX
#include <float.h>
#include <iostream>
using namespace std;
template <class T> inline double basic_distance(T a,T b) {
if (b == 0) {
......@@ -68,5 +71,5 @@ public:
}
};
#endif __DELAY_H
#endif
......@@ -6,24 +6,12 @@
#include "port.h"
#include <hash_map>
#include <slist>
#include <rope>
#include <hash_set>
#include <boost/config.hpp>
#include <boost/utility.hpp>
#include <boost/property_map.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <iostream.h>
using namespace boost;
using namespace boost;
#include "common.h"
#include "delay.h"
#include "physical.h"
#include "parser.h"
......
......@@ -6,11 +6,6 @@
#include "port.h"
#include <hash_map>
#include <slist>
#include <queue>
#include <rope>
#include <boost/config.hpp>
#include <boost/utility.hpp>
#include <boost/property_map.hpp>
......@@ -27,6 +22,7 @@ using namespace boost;
#include "physical.h"
#include "virtual.h"
#include "parser.h"
#include "anneal.h"
extern name_vvertex_map vname2vertex;
extern name_name_map fixed_nodes;
......
......@@ -4,14 +4,10 @@
* All rights reserved.
*/
#include <vector>
#include <rope>
#include <algo.h>
#include <iostream.h>
#include "parser.h"
#include <iostream>
#ifdef DEBUG_PARSER
#define DEBUG(x) x
#else
......
......@@ -7,11 +7,15 @@
#ifndef __PARSER_H
#define __PARSER_H
#include "port.h"
#include <vector>
using namespace std;
typedef vector<crope> string_vector;
int split_two(crope line,char split_char,crope &a,crope &b);
int split_two(crope line,char split_char,crope &a,crope &b,crope default_b);
string_vector split_line(crope line,char split_char);
#endif
......@@ -8,12 +8,21 @@
#include <stdlib.h>
#include <hash_map>
#include <rope>
#include <queue>
#include <list>
#include <algorithm>
/*
* We have to do these includes differently depending on which version of gcc
* we're compiling with
*/
#if __GNUC__ == 3 && __GNUC_MINOR__ > 0
#include <ext/hash_map>
using namespace __gnu_cxx;
#else
#include <hash_map>
#endif
#include <boost/config.hpp>
#include <boost/utility.hpp>
#include <boost/property_map.hpp>
......
......@@ -8,7 +8,30 @@
#define __PHYSICAL_H
#include "common.h"
#include <set>
#include <list>
using namespace std;
#include <boost/config.hpp>
#include <boost/utility.hpp>
#include <boost/property_map.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
using namespace boost;
/*
* We have to do these includes differently depending on which version of gcc
* we're compiling with
*/
#if __GNUC__ == 3 && __GNUC_MINOR__ > 0
#include <ext/hash_set>
#include <ext/hash_map>
using namespace __gnu_cxx;
#else
#include <hash_set>
#include <hash_map>
#endif
// Icky, but I can't include virtual.h here
class tb_vnode;
......
......@@ -5,8 +5,24 @@
*/
// This file may need to be changed depending on the architecture.
#ifndef __PORT_H
#include <limits.h>
#define WCHAR_MIN INT_MIN
#define WCHAR_MAX INT_MAX
/*
* We have to do these includes differently depending on which version of gcc
* we're compiling with
*/
#if __GNUC__ == 3 && __GNUC_MINOR__ > 0
#include <ext/rope>
using namespace __gnu_cxx;
#else
#include <rope>
#endif
#else
#define PORT_H
#endif
......@@ -10,11 +10,18 @@
#include <iostream.h>
#include <float.h>
/*
* We have to do these includes differently depending on which version of gcc
* we're compiling with
*/
#if __GNUC__ == 3 && __GNUC_MINOR__ > 0
#include <ext/hash_map>
#include <ext/hash_set>
using namespace __gnu_cxx;
#else
#include <hash_map>
#include <rope>
#include <queue>
#include <slist>
#include <hash_set>
#endif
#include <boost/config.hpp>
#include <boost/utility.hpp>
......@@ -302,8 +309,10 @@ void unscore_link_info(vedge ve,tb_pnode *src_pnode,tb_pnode *dst_pnode, tb_vnod
if (old_over_bw) {
// Count how many multiples of the maximum bandwidth we're at
int num_violations = (int)(floor((old_bw -1)/src_pnode->trivial_bw)
- floor((src_pnode->trivial_bw_used -1) / src_pnode->trivial_bw));
int num_violations = (int)(
floor((double)(old_bw -1)/src_pnode->trivial_bw)
- floor((double)(src_pnode->trivial_bw_used -1) /
src_pnode->trivial_bw));
violated -= num_violations;
vinfo.bandwidth -= num_violations;
double removed_bandwidth_percent = (old_over_bw - new_over_bw) * 1.0 /
......@@ -622,8 +631,9 @@ void score_link_info(vedge ve, tb_pnode *src_pnode, tb_pnode *dst_pnode, tb_vnod
if (new_over_bw) {
// Count how many multiples of the maximum bandwidth we're at
int num_violations =
(int)(floor((src_pnode->trivial_bw_used -1) / src_pnode->trivial_bw)
- floor((old_bw -1)/src_pnode->trivial_bw));
(int)(floor((double)((src_pnode->trivial_bw_used -1)
/ src_pnode->trivial_bw))
- floor((double)((old_bw -1)/src_pnode->trivial_bw)));
violated += num_violations;
vinfo.bandwidth += num_violations;
......@@ -1057,7 +1067,7 @@ int add_node(vvertex vv,pvertex pv, bool deterministic, bool is_fixed)
int index;
if (!deterministic && !greedy_link_assignment) {
float choice;
choice = std::random()%(int)total_weight;
choice = random()%(int)total_weight;
for (index = 0;index < resolution_index;++index) {
switch (resolutions[index].type_used) {
case tb_link_info::LINK_DIRECT:
......@@ -1405,8 +1415,8 @@ void score_link(pedge pe,vedge ve,tb_pnode *src_pnode, tb_pnode *dst_pnode)
if (new_over_bw) {
// Count how many multiples of the maximum bandwidth we're at
int num_violations =
(int)(floor((plink->bw_used -1) / plink->delay_info.bandwidth)
- floor((old_bw -1)/plink->delay_info.bandwidth));
(int)(floor((double)((plink->bw_used -1) / plink->delay_info.bandwidth))
- floor((double)((old_bw -1)/plink->delay_info.bandwidth)));
violated += num_violations;
vinfo.bandwidth += num_violations;
......@@ -1553,8 +1563,9 @@ void unscore_link(pedge pe,vedge ve, tb_pnode *src_pnode, tb_pnode *dst_pnode)
if (old_over_bw) {
// Count how many multiples of the maximum bandwidth we're at
int num_violations = (int)(floor((old_bw -1)/plink->delay_info.bandwidth)
- floor((plink->bw_used -1) / plink->delay_info.bandwidth));
int num_violations = (int)
(floor((double)((old_bw -1)/plink->delay_info.bandwidth))
- floor((double)((plink->bw_used -1) / plink->delay_info.bandwidth)));
violated -= num_violations;
vinfo.bandwidth -= num_violations;
double removed_bandwidth_percent = (old_over_bw - new_over_bw) * 1.0 /
......
......@@ -5,6 +5,7 @@
*/
#include "solution.h"
#include "vclass.h"
bool compare_scores(double score1, double score2) {
if ((score1 < (score2 + ITTY_BITTY)) && (score1 > (score2 - ITTY_BITTY))) {
......
......@@ -14,17 +14,9 @@
#include "port.h"
#include <boost/graph/adjacency_list.hpp>
using namespace boost;
#include <rope>
#include <queue>
#include "common.h"
#include "delay.h"
#include "physical.h"
#include "virtual.h"
#include "vclass.h"
#include "maps.h"
/*
......
......@@ -8,11 +8,6 @@
#include <stdlib.h>
#include <hash_map>
#include <rope>
#include <queue>
#include <slist>
#include <boost/config.hpp>
#include <boost/utility.hpp>
#include <boost/property_map.hpp>
......@@ -82,10 +77,10 @@ crope tb_vclass::choose_type()
{
// This may take some tweaking - i.e. might want to make more
// efficient, although members is usually a very small hash.
if (std::random()%2 == 0) {
if (random()%2 == 0) {
return dominant;
}
int r = std::random()%members.size();
int r = random()%members.size();
members_map::iterator dit;
for (dit=members.begin();dit != members.end();++dit) {
if (r == 0) break;
......
......@@ -7,6 +7,22 @@
#ifndef __VCLASS_H
#define __VCLASS_H
#include "port.h"
/*
* We have to do these includes differently depending on which version of gcc
* we're compiling with
*/
#if __GNUC__ == 3 && __GNUC_MINOR__ > 0
#include <ext/hash_map>
using namespace __gnu_cxx;
#else
#include <hash_map>
#endif
#include <iostream>
using namespace std;
// tb_vclass represents a virtual equivalence class. The main purpose
// of the code here is to monitor which members of the class are being
// used, what types that are being used as, and calculating the
......@@ -17,7 +33,6 @@
// stores which vclass it belongs to. This class is more abstract and
// represents the scoring model.
class tb_vclass {
public:
tb_vclass(crope n,double w) : name(n), weight(w), score(0) {;}
......
......@@ -7,7 +7,20 @@
#ifndef __VIRTUAL_H
#define __VIRTUAL_H
#include <hash_set>
/*
* We have to do these includes differently depending on which version of gcc
* we're compiling with
*/
#if __GNUC__ == 3 && __GNUC_MINOR__ > 0
#include <backward/queue.h>
#else
#include <queue>
#endif
#include <vector>
#include <list>
using namespace std;
class tb_plink;
class tb_vnode;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment