[Openmp-commits] [PATCH] D13175: Added sockets to the syntax of KMP_PLACE_THREADS environment variable.
Jim Cownie via Openmp-commits
openmp-commits at lists.llvm.org
Mon Sep 28 02:40:04 PDT 2015
jcownie added a subscriber: jcownie.
jcownie added a comment.
Can't we roll this up into something which is more table-driven (or loopy) ? (Something more like the code in the testbed runtime, which, admittedly, doesn't parse this yet, but clearly could quite easily.
Note that there's a loop here that extracts the sub-components of the string, then another loop to process them, rather than having five blocks of code, much of which is replicated.
static void parsePlaceThreads(char const * text, int * sockets, int * coresPerSocket, int *threadsPerCore)
{
// Default is (quoting Manuel) "I know nothing". (Vide Fawlty Towers...)
*sockets = *coresPerSocket = *threadsPerCore = 0;
if (!text)
return;
// We have something...
// Split the input into strings at 'x','X' or ','
std::string components[unknown_e];
std::string value = text;
size_t base = 0;
for (int i=0; i<unknown_e; i++)
{
int sepPos = value.find('x',base);
if (sepPos == std::string::npos)
{
sepPos = value.find('X',base);
if (sepPos == std::string::npos)
sepPos = value.find (',', base);
}
if (sepPos == std::string::npos)
{
components[i] = std::string (value, base, value.length());
break;
}
else
{
size_t len = sepPos - base;
components[i] = std::string (value, base, len);
}
base = sepPos+1;
}
// Actually we found nothing
if (components[0].length() == 0)
return;
bool seen[unknown_e];
for (int i=0; i<unknown_e; i++)
seen[i] = false;
// Check each component
for (int i=0; i<unknown_e; i++)
{
if (components[i].length() == 0)
break;
componentType_e what = getType (components[i]);
if (what == unknown_e)
{
what = componentType_e(i);
if (seen[what])
what = componentType_e(((int)what)+1);
}
if (seen[what] || what == unknown_e)
{
fatalError ("Cannot parse KMP_PLACE_THREADS (duplicate field): %s.", text);
}
else
{
seen[what] = true;
}
char const * start = components[i].c_str();
char * end = 0;
long int value = strtol(start, &end, 0);
if (end == start)
{
fatalError ("Cannot parse KMP_PLACE_THREADS (failed to parse a number): %s.", text);
}
if (*end == '@')
{
fatalError("Offsets in KMP_PLACE_THREADS are not currently supported: %s.", text);
}
switch (what)
{
case sockets_e: *sockets = value; break;
case cores_e: *coresPerSocket = value; break;
case threads_e: *threadsPerCore = value; break;
}
}
}
Repository:
rL LLVM
http://reviews.llvm.org/D13175
More information about the Openmp-commits
mailing list