Commit a75155ae authored by Robert Ricci's avatar Robert Ricci

Resurrect the 'cparams' support: allow callers to pass in a bunch of

values for configuration parameters, such as some of the cooling
parameters, scoring values, etc.

Also add a -D option to dump these parametrs, as well as the command
line, for posterity.

Refresh the dependency list at the end of the makefile
parent 31977337
...@@ -24,7 +24,8 @@ all: assign ...@@ -24,7 +24,8 @@ all: assign
include $(TESTBED_SRCDIR)/GNUmakerules include $(TESTBED_SRCDIR)/GNUmakerules
OBJS=parse_top.o parse_ptop.o assign.o pclass.o vclass.o score.o \ OBJS=parse_top.o parse_ptop.o assign.o pclass.o vclass.o score.o \
parser.o solution.o anneal.o featuredesire.o neighborhood.o fstring.o parser.o solution.o anneal.o featuredesire.o neighborhood.o fstring.o \
config.o
LIBS+= -lm LIBS+= -lm
LDFLAGS+= -pipe -O3 LDFLAGS+= -pipe -O3
CXXFLAGS = -pipe -I/usr/local/include -ftemplate-depth-40 CXXFLAGS = -pipe -I/usr/local/include -ftemplate-depth-40
...@@ -95,15 +96,12 @@ clean: ...@@ -95,15 +96,12 @@ clean:
anneal.o: anneal.cc anneal.h port.h delay.h physical.h common.h fstring.h \ anneal.o: anneal.cc anneal.h port.h delay.h physical.h common.h fstring.h \
featuredesire.h forwarding.h pclass.h virtual.h maps.h score.h \ featuredesire.h forwarding.h pclass.h virtual.h maps.h score.h \
solution.h vclass.h neighborhood.h solution.h vclass.h neighborhood.h
annotate.o: annotate.cc
annotate_rspec.o: annotate_rspec.cc
annotate_vtop.o: annotate_vtop.cc
assign.o: assign.cc port.h common.h fstring.h delay.h physical.h \ assign.o: assign.cc port.h common.h fstring.h delay.h physical.h \
featuredesire.h forwarding.h virtual.h vclass.h pclass.h score.h \ featuredesire.h forwarding.h virtual.h vclass.h pclass.h score.h \
solution.h maps.h anneal.h config.h parse_advertisement_rspec.h parse_ptop_xml.h xmlhelpers.h \ solution.h maps.h anneal.h config.h
xstr.h parse_request_rspec.h parse_vtop_xml.h
annotate.o: annotate.cc annotate.h
annotate_rspec.o: annotate.cc annotate.h annotate_rspec.cc annotate_rspec.h \
xmlhelpers.h xstr.h
annotate_vtop.o: annotate.cc annotate.h annotate_vtop.cc annotate_vtop.h \
xmlhelpers.h xstr.h
config.o: config.cc config.h common.h port.h fstring.h score.h physical.h \ config.o: config.cc config.h common.h port.h fstring.h score.h physical.h \
delay.h featuredesire.h forwarding.h virtual.h anneal.h pclass.h delay.h featuredesire.h forwarding.h virtual.h anneal.h pclass.h
featuredesire.o: featuredesire.cc featuredesire.h common.h port.h \ featuredesire.o: featuredesire.cc featuredesire.h common.h port.h \
...@@ -115,35 +113,18 @@ fstringtest.o: fstringtest.cc fstring.h port.h ...@@ -115,35 +113,18 @@ fstringtest.o: fstringtest.cc fstring.h port.h
neighborhood.o: neighborhood.cc neighborhood.h port.h common.h fstring.h \ neighborhood.o: neighborhood.cc neighborhood.h port.h common.h fstring.h \
physical.h delay.h featuredesire.h forwarding.h vclass.h virtual.h \ physical.h delay.h featuredesire.h forwarding.h vclass.h virtual.h \
pclass.h pclass.h
parse_error_handler.o: parse_error_handler.cc parse_error_handler.h \ parse_advertisement_rspec.o: parse_advertisement_rspec.cc
xmlhelpers.h featuredesire.h common.h port.h fstring.h xstr.h parse_error_handler.o: parse_error_handler.cc
parse_policy_xml.o: parse_policy_xml.cc parse_policy_xml.h physical.h \ parse_policy_xml.o: parse_policy_xml.cc
common.h port.h fstring.h delay.h featuredesire.h forwarding.h \
xmlhelpers.h xstr.h parse_error_handler.h
parse_ptop.o: parse_ptop.cc port.h delay.h physical.h common.h fstring.h \ parse_ptop.o: parse_ptop.cc port.h delay.h physical.h common.h fstring.h \
featuredesire.h forwarding.h parser.h featuredesire.h forwarding.h parser.h
parse_ptop_xml.o: parse_ptop_xml.cc parse_ptop_xml.h physical.h common.h \ parse_ptop_xml.o: parse_ptop_xml.cc
port.h fstring.h delay.h featuredesire.h forwarding.h xmlhelpers.h \ parse_request_rspec.o: parse_request_rspec.cc
xstr.h parse_error_handler.h
parser.o: parser.cc parser.h port.h
parse_advertisement_rspec.o: parse_advertisement_rspec.cc parse_advertisement_rspec.h \
common.h port.h fstring.h delay.h featuredesire.h forwarding.h \
xmlhelpers.h xstr.h parse_error_handler.h anneal.h
parse_request_rspec.o: parse_request_rspec.cc parse_request_rspec.h \
common.h port.h fstring.h delay.h featuredesire.h forwarding.h \
virtual.h xmlhelpers.h xstr.h parse_error_handler.h anneal.h \
vclass.h
parse_top.o: parse_top.cc port.h common.h fstring.h vclass.h delay.h \ parse_top.o: parse_top.cc port.h common.h fstring.h vclass.h delay.h \
physical.h featuredesire.h forwarding.h virtual.h parser.h anneal.h \ physical.h featuredesire.h forwarding.h virtual.h parser.h anneal.h \
pclass.h pclass.h
parse_vtop_rspec.o: parse_vtop_rspec.cc parse_vtop_rspec.h \ parse_vtop_xml.o: parse_vtop_xml.cc
common.h port.h fstring.h delay.h featuredesire.h forwarding.h \ parser.o: parser.cc parser.h port.h
virtual.h xmlhelpers.h xstr.h parse_error_handler.h anneal.h \
vclass.h
parse_vtop_xml.o: parse_vtop_xml.cc port.h common.h fstring.h vclass.h \
delay.h physical.h featuredesire.h forwarding.h virtual.h parser.h \
anneal.h pclass.h parse_vtop_xml.h xmlhelpers.h xstr.h \
parse_error_handler.h
pclass.o: pclass.cc port.h common.h fstring.h delay.h physical.h \ pclass.o: pclass.cc port.h common.h fstring.h delay.h physical.h \
featuredesire.h forwarding.h virtual.h pclass.h featuredesire.h forwarding.h virtual.h pclass.h
score.o: score.cc port.h common.h fstring.h vclass.h delay.h physical.h \ score.o: score.cc port.h common.h fstring.h vclass.h delay.h physical.h \
...@@ -152,5 +133,4 @@ solution.o: solution.cc solution.h port.h delay.h physical.h common.h \ ...@@ -152,5 +133,4 @@ solution.o: solution.cc solution.h port.h delay.h physical.h common.h \
fstring.h featuredesire.h forwarding.h virtual.h maps.h vclass.h fstring.h featuredesire.h forwarding.h virtual.h maps.h vclass.h
vclass.o: vclass.cc port.h common.h fstring.h vclass.h delay.h physical.h \ vclass.o: vclass.cc port.h common.h fstring.h vclass.h delay.h physical.h \
featuredesire.h forwarding.h virtual.h featuredesire.h forwarding.h virtual.h
xmlhelpers.o: xmlhelpers.cc xmlhelpers.h featuredesire.h common.h port.h \ xmlhelpers.o: xmlhelpers.cc
fstring.h xstr.h
/* /*
* EMULAB-COPYRIGHT * EMULAB-COPYRIGHT
* Copyright (c) 2000-2006 University of Utah and the Flux Group. * Copyright (c) 2000-2009 University of Utah and the Flux Group.
* All rights reserved. * All rights reserved.
*/ */
...@@ -133,6 +133,9 @@ double use_connected_pnode_find = 0.0f; ...@@ -133,6 +133,9 @@ double use_connected_pnode_find = 0.0f;
// Whether or not to perform all checks on fixed nodes // Whether or not to perform all checks on fixed nodes
bool check_fixed_nodes = false; bool check_fixed_nodes = false;
// If true, dump a bunch of configrution information
bool dump_config = false;
// Use XML for file input // Use XML for file input
// bool xml_input = false; // bool xml_input = false;
#ifdef WITH_XML #ifdef WITH_XML
...@@ -416,7 +419,7 @@ void prune_unusable_pclasses() { ...@@ -416,7 +419,7 @@ void prune_unusable_pclasses() {
} }
void print_help() { void print_help() {
cout << "assign [options] ptopfile topfile [config params]" << endl; cout << "assign [options] ptopfile topfile [cparams]" << endl;
cout << "Options: " << endl; cout << "Options: " << endl;
#ifdef TIME_TERMINATE #ifdef TIME_TERMINATE
cout << " -l <time> - Limit runtime." << endl; cout << " -l <time> - Limit runtime." << endl;
...@@ -439,7 +442,7 @@ void print_help() { ...@@ -439,7 +442,7 @@ void print_help() {
<< endl; << endl;
cout << " -u - Print a summary of the solution." << endl; cout << " -u - Print a summary of the solution." << endl;
cout << " -c <float> - Use the 'connected' pnode finding algorithm " << cout << " -c <float> - Use the 'connected' pnode finding algorithm " <<
"<float>*100% of the time." << endl; "<float>*100%" << endl << " of the time." << endl;
cout << " -n - Don't anneal - just do the prechecks." << endl; cout << " -n - Don't anneal - just do the prechecks." << endl;
cout << " -x <file> - Specify a text ptop file" << endl; cout << " -x <file> - Specify a text ptop file" << endl;
...@@ -454,7 +457,11 @@ void print_help() { ...@@ -454,7 +457,11 @@ void print_help() {
cout << " -q <file> - Specify a rspec ptop file" << endl; cout << " -q <file> - Specify a rspec ptop file" << endl;
cout << " -w <file> - Specify a rspec vtop file" << endl; cout << " -w <file> - Specify a rspec vtop file" << endl;
#endif #endif
cout << " -F - Apply additional checking to fixed noded" << endl; cout << " -F - Apply additional checking to fixed nodes" << endl;
cout << " -D - Dump configuration options" << endl;
cout << " cparams - You probably don't want to touch these!" << endl;
cout << " If you must, see config.h in the source for a list"
<< endl;
exit(EXIT_FATAL); exit(EXIT_FATAL);
} }
...@@ -842,7 +849,7 @@ int main(int argc,char **argv) { ...@@ -842,7 +849,7 @@ int main(int argc,char **argv) {
char* ptopFilename = ""; char* ptopFilename = "";
char* vtopFilename = ""; char* vtopFilename = "";
while ((ch = getopt(argc,argv,"s:v:l:t:rpPTdH:oguc:nx:X:y:Y:q:w:F")) != -1) { while ((ch = getopt(argc,argv,"s:v:l:t:rpPTdH:oguc:nx:X:y:Y:q:w:FD")) != -1) {
switch (ch) { switch (ch) {
case 's': case 's':
if (sscanf(optarg,"%d",&seed) != 1) { if (sscanf(optarg,"%d",&seed) != 1) {
...@@ -905,6 +912,9 @@ int main(int argc,char **argv) { ...@@ -905,6 +912,9 @@ int main(int argc,char **argv) {
prechecks_only = true; prechecks_only = true;
cout << "Doing only prechecks, exiting early" << endl; cout << "Doing only prechecks, exiting early" << endl;
break; break;
case 'D':
dump_config = true;
break;
case 'x': case 'x':
#ifdef WITH_XML #ifdef WITH_XML
ptop_xml_input = false; ptop_xml_input = false;
...@@ -966,13 +976,30 @@ int main(int argc,char **argv) { ...@@ -966,13 +976,30 @@ int main(int argc,char **argv) {
print_help(); print_help();
} }
} }
// Save argv and argc, and advance past the initial options
char **oldargv = argv;
int oldargc = argc;
argc -= optind; argc -= optind;
argv += optind; argv += optind;
if (strcmp(ptopFilename, "") == 0 && argc >= 1) {
ptopFilename = argv[0];
argc -= 1;
argv += 1;
}
if (strcmp(vtopFilename, "") == 0 && argc >= 1) {
vtopFilename = argv[0];
argc -= 1;
argv += 1;
}
if (argc == 2) if (argc > 0)
{ {
ptopFilename = argv[0]; // If there are still more options, they must be from the common.h
vtopFilename = argv[1]; // parameters.
parse_options(argv, options, noptions);
} }
if (strcmp(ptopFilename, "") == 0) if (strcmp(ptopFilename, "") == 0)
...@@ -1018,12 +1045,6 @@ int main(int argc,char **argv) { ...@@ -1018,12 +1045,6 @@ int main(int argc,char **argv) {
sigaction(SIGINFO,&action2,NULL); sigaction(SIGINFO,&action2,NULL);
#endif #endif
// Convert options to the common.h parameters.
//parse_options(argv, options, noptions);
#ifdef SCORE_DEBUG
//dump_options("Configuration options:", options, noptions);
#endif
#ifdef GNUPLOT_OUTPUT #ifdef GNUPLOT_OUTPUT
scoresout = fopen("scores.out","w"); scoresout = fopen("scores.out","w");
tempout = fopen("temp.out","w"); tempout = fopen("temp.out","w");
...@@ -1033,6 +1054,16 @@ int main(int argc,char **argv) { ...@@ -1033,6 +1054,16 @@ int main(int argc,char **argv) {
cout << "seed = " << seed << endl; cout << "seed = " << seed << endl;
srandom(seed); srandom(seed);
// Print out information about how we were called
if (dump_config) {
cout << "Command line:";
for (int i = 0; i < oldargc; i++) {
cout << " " << oldargv[i];
}
cout << endl;
dump_options("Config parameters", options, noptions);
}
read_physical_topology(ptopFilename); read_physical_topology(ptopFilename);
calculate_switch_MST(); calculate_switch_MST();
......
/* /*
* EMULAB-COPYRIGHT * EMULAB-COPYRIGHT
* Copyright (c) 2002-2003 University of Utah and the Flux Group. * Copyright (c) 2002-2009 University of Utah and the Flux Group.
* All rights reserved. * All rights reserved.
*/ */
static const char rcsid[] = "$Id: config.cc,v 1.5 2009-05-20 18:06:08 tarunp Exp $"; static const char rcsid[] = "$Id: config.cc,v 1.6 2009-06-16 21:11:05 ricci Exp $";
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -21,33 +21,49 @@ parse_options(char **argv, struct config_param opts[], int nopt) ...@@ -21,33 +21,49 @@ parse_options(char **argv, struct config_param opts[], int nopt)
{ {
extern char **environ; extern char **environ;
/* get from environment first */ /* get from environment first - just skip unknown environment variables */
config_parse(environ, opts, nopt); config_parse(environ, opts, nopt, false);
/* then command line */ /* then command line - die if given bad option */
config_parse(argv, opts, nopt); config_parse(argv, opts, nopt, true);
} }
int int
config_parse(char **args, struct config_param cparams[], int nparams) config_parse(char **args, struct config_param cparams[], int nparams,
bool exit_on_error)
{ {
int i, j, len; int i, j, len;
char *arg, *var, *val, buf[256]; char *arg, *var, *val, buf[256];
for (i = 0, arg = args[i]; arg != 0; i++, arg = args[i]) { for (i = 0, arg = args[i]; arg != NULL; i++, arg = args[i]) {
len = sizeof(buf) - 1; len = sizeof(buf) - 1;
strncpy(buf, arg, len); strncpy(buf, arg, len);
buf[len] = 0; buf[len] = 0;
var = val = buf; var = val = buf;
if (strsep(&val, "=") == 0 || val == 0 || *val == 0) if (strsep(&val, "=") == 0 || val == 0 || *val == 0) {
continue; if (exit_on_error) {
cout << "*** Expected a configuration parameter, got "
<< arg << endl;
exit(EXIT_FATAL);
} else {
continue;
}
}
for (j = 0; j < nparams; j++) for (j = 0; j < nparams; j++)
if (strcmp(var, cparams[j].name) == 0) if (strcmp(var, cparams[j].name) == 0)
break; break;
if (j == nparams)
continue;
if (j == nparams) {
if (exit_on_error) {
cout << "*** Bad configuration parameter name: " << var << endl;
exit(EXIT_FATAL);
} else {
continue;
}
}
// Note: Unused
if (cparams[j].func) { if (cparams[j].func) {
cparams[j].func(&cparams[j], val); cparams[j].func(&cparams[j], val);
continue; continue;
...@@ -60,14 +76,6 @@ config_parse(char **args, struct config_param cparams[], int nparams) ...@@ -60,14 +76,6 @@ config_parse(char **args, struct config_param cparams[], int nparams)
case CONFIG_FLOAT: case CONFIG_FLOAT:
*(float *)cparams[j].ptr = (float) atof(val); *(float *)cparams[j].ptr = (float) atof(val);
break; break;
/*
case CONFIG_STRING:
bp = malloc(strlen(val) + 1);
assert(bp);
strcpy(bp, val);
*(char **)cparams[j].ptr = bp;
break;
*/
} }
} }
...@@ -79,7 +87,7 @@ dump_options(const char *str, struct config_param cparams[], int numparams) ...@@ -79,7 +87,7 @@ dump_options(const char *str, struct config_param cparams[], int numparams)
{ {
int i; int i;
fprintf(stderr,"%s configuration:\n", str); fprintf(stderr,"%s:\n", str);
for (i = 0; i < numparams; i++) { for (i = 0; i < numparams; i++) {
fprintf(stderr," %s ", cparams[i].name); fprintf(stderr," %s ", cparams[i].name);
switch (cparams[i].type) { switch (cparams[i].type) {
...@@ -91,12 +99,6 @@ dump_options(const char *str, struct config_param cparams[], int numparams) ...@@ -91,12 +99,6 @@ dump_options(const char *str, struct config_param cparams[], int numparams)
fprintf(stderr,"%f\n", fprintf(stderr,"%f\n",
*(float *)cparams[i].ptr); *(float *)cparams[i].ptr);
break; break;
/*
case CONFIG_STRING:
fprintf(stderr,"%s\n", *(char **)cparams[i].ptr ?
*(char **)cparams[i].ptr : "<unset>");
break;
*/
} }
} }
} }
/* /*
* EMULAB-COPYRIGHT * EMULAB-COPYRIGHT
* Copyright (c) 1999-2003 The University of Utah and the Flux Group. * Copyright (c) 1999-2009 The University of Utah and the Flux Group.
* All rights reserved. * All rights reserved.
*/ */
...@@ -11,10 +11,6 @@ ...@@ -11,10 +11,6 @@
#include "score.h" #include "score.h"
#include "anneal.h" #include "anneal.h"
#ifdef __cplusplus
extern "C" {
#endif
/* /*
* Dumb as a stump config for options that the test program supports * Dumb as a stump config for options that the test program supports
*/ */
...@@ -23,7 +19,7 @@ struct config_param { ...@@ -23,7 +19,7 @@ struct config_param {
int type; /* type (see below) */ int type; /* type (see below) */
void *ptr; /* pointer to value portion */ void *ptr; /* pointer to value portion */
void (*func)(struct config_param *opt, char *newval); void (*func)(struct config_param *opt, char *newval);
/* function to set value */ /* function to set value (unused) */
}; };
/* types */ /* types */
...@@ -31,14 +27,10 @@ struct config_param { ...@@ -31,14 +27,10 @@ struct config_param {
#define CONFIG_FLOAT 1 #define CONFIG_FLOAT 1
void parse_options(char **argv, struct config_param options[], int nopt); void parse_options(char **argv, struct config_param options[], int nopt);
int config_parse(char **args, struct config_param cparams[], int nparams); int config_parse(char **args, struct config_param cparams[], int nparams,
bool exit_on_error);
void dump_options(const char *str, struct config_param cparams[], int nparams); void dump_options(const char *str, struct config_param cparams[], int nparams);
#ifdef __cplusplus
}
#endif
/* /*
* To use these on the command line, each entry gets a * To use these on the command line, each entry gets a
* <name>=<value> pair on the command line. * <name>=<value> pair on the command line.
......
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