"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Common/Message.cpp" between
getdp-3.4.0-source.tgz and getdp-3.5.0-source.tgz

About: GetDP is a general finite element solver using mixed elements to discretize de Rham-type complexes in one, two and three dimensions.

Message.cpp  (getdp-3.4.0-source.tgz):Message.cpp  (getdp-3.5.0-source.tgz)
// GetDP - Copyright (C) 1997-2021 P. Dular and C. Geuzaine, University of Liege // GetDP - Copyright (C) 1997-2022 P. Dular and C. Geuzaine, University of Liege
// //
// See the LICENSE.txt file for license information. Please report all // See the LICENSE.txt file for license information. Please report all
// issues on https://gitlab.onelab.info/getdp/getdp/issues. // issues on https://gitlab.onelab.info/getdp/getdp/issues.
#include <clocale> #include <clocale>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include <time.h> #include <time.h>
#include <algorithm> #include <algorithm>
skipping to change at line 63 skipping to change at line 63
#include <octave/oct.h> #include <octave/oct.h>
#include <octave/octave.h> #include <octave/octave.h>
#include <octave/toplev.h> #include <octave/toplev.h>
#endif #endif
#if defined(HAVE_PYTHON) #if defined(HAVE_PYTHON)
#undef HAVE_DLOPEN #undef HAVE_DLOPEN
#include <Python.h> #include <Python.h>
#endif #endif
#if defined(HAVE_HPDDM)
#define MUMPSSUB // direct mumps solver for subdomain solves
#define DMUMPS // direct mumps solver for the coarse solves
#define HPDDM_NUMBERING 'C' // 0-based numering
#define HPDDM_NO_REGEX
#undef NONE
#include <HPDDM.hpp>
#endif
int Message::_commRank = 0; int Message::_commRank = 0;
int Message::_commSize = 1; int Message::_commSize = 1;
int Message::_isCommWorld = 1; // is the communicator set to WORLD (==1) or SELF int Message::_isCommWorld =
(!=1) 1; // is the communicator set to WORLD (==1) or SELF (!=1)
int Message::_errorCount = 0; int Message::_errorCount = 0;
int Message::_lastPETScError = 0; int Message::_lastPETScError = 0;
int Message::_exitOnError = 0; int Message::_exitOnError = 0;
bool Message::_operatingInTimeLoopAdaptive = false; bool Message::_operatingInTimeLoopAdaptive = false;
int Message::_verbosity = 5; int Message::_verbosity = 5;
int Message::_progressMeterStep = 10; int Message::_progressMeterStep = 10;
int Message::_progressMeterCurrent = 0; int Message::_progressMeterCurrent = 0;
bool Message::_infoCpu = false; bool Message::_infoCpu = false;
double Message::_startTime = 0.; double Message::_startTime = 0.;
std::map<std::string, double> Message::_timers; std::map<std::string, double> Message::_timers;
GmshClient* Message::_client = 0; GmshClient *Message::_client = 0;
onelab::client* Message::_onelabClient = 0; onelab::client *Message::_onelabClient = 0;
#if !defined(HAVE_ONELAB) // if Gmsh is compiled without onelab #if !defined(HAVE_ONELAB) // if Gmsh is compiled without onelab
onelab::server *onelab::server::_server = 0; onelab::server *onelab::server::_server = 0;
#endif #endif
#if defined(HAVE_NO_VSNPRINTF) #if defined(HAVE_NO_VSNPRINTF)
static int vsnprintf(char *str, size_t size, const char *fmt, va_list ap) static int vsnprintf(char *str, size_t size, const char *fmt, va_list ap)
{ {
if(strlen(fmt) > size - 1){ // just copy the format if(strlen(fmt) > size - 1) { // just copy the format
strncpy(str, fmt, size - 1); strncpy(str, fmt, size - 1);
str[size - 1] = '\0'; str[size - 1] = '\0';
return size; return size;
} }
return vsprintf(str, fmt, ap); return vsprintf(str, fmt, ap);
} }
#endif #endif
#if defined(_MSC_VER) && (_MSC_VER == 1310) //NET 2003 #if defined(_MSC_VER) && (_MSC_VER == 1310) // NET 2003
#define vsnprintf _vsnprintf #define vsnprintf _vsnprintf
#endif #endif
#if defined(HAVE_GSL) #if defined(HAVE_GSL)
static void gslErrorHandler(const char *reason, const char *file, int line, static void gslErrorHandler(const char *reason, const char *file, int line,
int gsl_errno) int gsl_errno)
{ {
Message::Error("GSL: %s (%s, line %d)", reason, file, line); Message::Error("GSL: %s (%s, line %d)", reason, file, line);
} }
#endif #endif
skipping to change at line 136 skipping to change at line 128
#if defined(HAVE_GSL) #if defined(HAVE_GSL)
gsl_set_error_handler(&gslErrorHandler); gsl_set_error_handler(&gslErrorHandler);
#endif #endif
#if defined(HAVE_OCTAVE) #if defined(HAVE_OCTAVE)
string_vector oargv(2); string_vector oargv(2);
oargv(0) = "embedded"; oargv(0) = "embedded";
oargv(1) = "-q"; oargv(1) = "-q";
octave_main(2, oargv.c_str_vec(), 1); octave_main(2, oargv.c_str_vec(), 1);
#endif #endif
#if defined(HAVE_PYTHON) #if defined(HAVE_PYTHON)
#if (PY_MAJOR_VERSION < 3) #if(PY_MAJOR_VERSION < 3)
Py_SetProgramName(argv[0]); Py_SetProgramName(argv[0]);
Py_InitializeEx(0); Py_InitializeEx(0);
PySys_SetArgv(argc, argv); PySys_SetArgv(argc, argv);
#else // requires Python 3.5 #else // requires Python 3.5
std::vector<wchar_t*> wargv(argc ? argc : 1); std::vector<wchar_t *> wargv(argc ? argc : 1);
for(int i = 0; i < argc; i++) for(int i = 0; i < argc; i++) wargv[i] = Py_DecodeLocale(argv[i], NULL);
wargv[i] = Py_DecodeLocale(argv[i], NULL);
Py_SetProgramName(wargv[0]); Py_SetProgramName(wargv[0]);
Py_InitializeEx(0); Py_InitializeEx(0);
PySys_SetArgv(argc, &wargv[0]); PySys_SetArgv(argc, &wargv[0]);
#endif #endif
#endif #endif
#if defined(HAVE_HPDDM)
HPDDM::Option& opt = *HPDDM::Option::get();
opt.parse(argc, argv, _commRank == 0);
#endif
// make sure to use the "C" locale; in particular this ensures that we will // make sure to use the "C" locale; in particular this ensures that we will
// use a dot for for the decimal separator when writing ASCII mesh files // use a dot for for the decimal separator when writing ASCII mesh files
std::setlocale(LC_ALL, "C"); std::setlocale(LC_ALL, "C");
std::setlocale(LC_NUMERIC, "C"); std::setlocale(LC_NUMERIC, "C");
} }
void Message::Finalize() void Message::Finalize()
{ {
#if defined(HAVE_PETSC) #if defined(HAVE_PETSC)
// don't call MPI_*() if _commSize == 1: newer PETSc does like it // don't call MPI_*() if _commSize == 1: newer PETSc does like it
if(_commSize > 1){ if(_commSize > 1) {
int initialized, finalized; int initialized, finalized;
MPI_Initialized(&initialized); MPI_Initialized(&initialized);
MPI_Finalized(&finalized); MPI_Finalized(&finalized);
if(initialized && !finalized) if(initialized && !finalized) MPI_Finalize();
MPI_Finalize();
} }
#endif #endif
FinalizeSocket(); FinalizeSocket();
FinalizeOnelab(); FinalizeOnelab();
#if defined(HAVE_PYTHON) #if defined(HAVE_PYTHON)
// FIXME: this should be called, but it segfaults if the getdp lib is itself // FIXME: this should be called, but it segfaults if the getdp lib is itself
// wrapped into python with swig // wrapped into python with swig
//Py_Finalize(); // Py_Finalize();
#endif #endif
} }
void Message::Exit(int level) void Message::Exit(int level)
{ {
#if defined(HAVE_PETSC) #if defined(HAVE_PETSC)
if(level && _commSize > 1){ if(level && _commSize > 1) {
// abort (and not finalize) in order to terminate the full job *now* // abort (and not finalize) in order to terminate the full job *now*
MPI_Abort(MPI_COMM_WORLD, level); MPI_Abort(MPI_COMM_WORLD, level);
} }
#endif #endif
Finalize(); Finalize();
#if defined(HAVE_OCTAVE) #if defined(HAVE_OCTAVE)
clean_up_and_exit(level); clean_up_and_exit(level);
#else #else
exit(level); exit(level);
#endif #endif
} }
static int streamIsFile(FILE* stream) static int streamIsFile(FILE *stream)
{ {
// the given stream is definitely not interactive if it is a regular file // the given stream is definitely not interactive if it is a regular file
struct stat stream_stat; struct stat stream_stat;
if(fstat(fileno(stream), &stream_stat) == 0){ if(fstat(fileno(stream), &stream_stat) == 0) {
if(stream_stat.st_mode & S_IFREG) return 1; if(stream_stat.st_mode & S_IFREG) return 1;
} }
return 0; return 0;
} }
static int streamIsVT100(FILE* stream) static int streamIsVT100(FILE *stream)
{ {
// on unix directly check if the file descriptor refers to a terminal // on unix directly check if the file descriptor refers to a terminal
#if !defined(WIN32) || defined(__CYGWIN__) #if !defined(WIN32) || defined(__CYGWIN__)
return isatty(fileno(stream)); return isatty(fileno(stream));
#endif #endif
// otherwise try to detect some known cases: // otherwise try to detect some known cases:
// if running inside emacs the terminal is not VT100 // if running inside emacs the terminal is not VT100
const char* emacs = getenv("EMACS"); const char *emacs = getenv("EMACS");
if(emacs && *emacs == 't') return 0; if(emacs && *emacs == 't') return 0;
// list of known terminal names (from cmake) // list of known terminal names (from cmake)
static const char* names[] = static const char *names[] = {"Eterm",
{"Eterm", "ansi", "color-xterm", "con132x25", "con132x30", "con132x43", "ansi",
"con132x60", "con80x25", "con80x28", "con80x30", "con80x43", "con80x50", "color-xterm",
"con80x60", "cons25", "console", "cygwin", "dtterm", "eterm-color", "gnome "con132x25",
", "con132x30",
"gnome-256color", "konsole", "konsole-256color", "kterm", "linux", "msys", "con132x43",
"linux-c", "mach-color", "mlterm", "putty", "rxvt", "rxvt-256color", "con132x60",
"rxvt-cygwin", "rxvt-cygwin-native", "rxvt-unicode", "rxvt-unicode-256color "con80x25",
", "con80x28",
"screen", "screen-256color", "screen-256color-bce", "screen-bce", "screen-w "con80x30",
", "con80x43",
"screen.linux", "vt100", "xterm", "xterm-16color", "xterm-256color", "con80x50",
"xterm-88color", "xterm-color", "xterm-debian", 0}; "con80x60",
const char** t = 0; "cons25",
const char* term = getenv("TERM"); "console",
if(term){ "cygwin",
"dtterm",
"eterm-color",
"gnome",
"gnome-256color",
"konsole",
"konsole-256color",
"kterm",
"linux",
"msys",
"linux-c",
"mach-color",
"mlterm",
"putty",
"rxvt",
"rxvt-256color",
"rxvt-cygwin",
"rxvt-cygwin-native",
"rxvt-unicode",
"rxvt-unicode-256color",
"screen",
"screen-256color",
"screen-256color-bce",
"screen-bce",
"screen-w",
"screen.linux",
"vt100",
"xterm",
"xterm-16color",
"xterm-256color",
"xterm-88color",
"xterm-color",
"xterm-debian",
0};
const char **t = 0;
const char *term = getenv("TERM");
if(term) {
for(t = names; *t && strcmp(term, *t) != 0; ++t) {} for(t = names; *t && strcmp(term, *t) != 0; ++t) {}
} }
if(!(t && *t)) return 0; if(!(t && *t)) return 0;
return 1; return 1;
} }
void Message::Fatal(const char *fmt, ...) void Message::Fatal(const char *fmt, ...)
{ {
_errorCount++; _errorCount++;
char str[1024]; char str[1024];
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
vsnprintf(str, sizeof(str), fmt, args); vsnprintf(str, sizeof(str), fmt, args);
va_end(args); va_end(args);
if(_client){ if(_client) { _client->Error(str); }
_client->Error(str); else if(_onelabClient && _onelabClient->getName() != "GetDPServer") {
}
else if(_onelabClient && _onelabClient->getName() != "GetDPServer"){
_onelabClient->sendError(str); _onelabClient->sendError(str);
} }
else{ else {
const char *c0 = "", *c1 = ""; const char *c0 = "", *c1 = "";
if(!streamIsFile(stderr) && streamIsVT100(stderr)){ if(!streamIsFile(stderr) && streamIsVT100(stderr)) {
c0 = "\33[1m\33[31m"; c1 = "\33[0m"; // bold red c0 = "\33[1m\33[31m";
c1 = "\33[0m"; // bold red
} }
if(_commSize > 1) if(_commSize > 1)
fprintf(stderr, "%sFatal : [rank %3d] %s%s\n", c0, _commRank, str, c1); fprintf(stderr, "%sFatal : [rank %3d] %s%s\n", c0, _commRank, str, c1);
else else
fprintf(stderr, "%sFatal : %s%s\n", c0, str, c1); fprintf(stderr, "%sFatal : %s%s\n", c0, str, c1);
fflush(stderr); fflush(stderr);
} }
Exit(1); Exit(1);
} }
skipping to change at line 282 skipping to change at line 306
_errorCount++; _errorCount++;
if(!_exitOnError && _verbosity < 1) return; if(!_exitOnError && _verbosity < 1) return;
char str[1024]; char str[1024];
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
vsnprintf(str, sizeof(str), fmt, args); vsnprintf(str, sizeof(str), fmt, args);
va_end(args); va_end(args);
if(_client){ if(_client) { _client->Error(str); }
_client->Error(str); else if(_onelabClient && _onelabClient->getName() != "GetDPServer") {
}
else if(_onelabClient && _onelabClient->getName() != "GetDPServer"){
_onelabClient->sendError(str); _onelabClient->sendError(str);
} }
else{ else {
const char *c0 = "", *c1 = ""; const char *c0 = "", *c1 = "";
if(!streamIsFile(stderr) && streamIsVT100(stderr)){ if(!streamIsFile(stderr) && streamIsVT100(stderr)) {
c0 = "\33[1m\33[31m"; c1 = "\33[0m"; // bold red c0 = "\33[1m\33[31m";
c1 = "\33[0m"; // bold red
} }
if(_commSize > 1) if(_commSize > 1)
fprintf(stderr, "%sError : [rank %3d] %s%s\n", c0, _commRank, str, c1); fprintf(stderr, "%sError : [rank %3d] %s%s\n", c0, _commRank, str, c1);
else else
fprintf(stderr, "%sError : %s%s\n", c0, str, c1); fprintf(stderr, "%sError : %s%s\n", c0, str, c1);
fflush(stderr); fflush(stderr);
} }
if(_exitOnError == 1){ if(_exitOnError == 1) { Exit(1); }
Exit(1); else if(_exitOnError == 2) {
}
else if(_exitOnError == 2){
throw "GetDP error"; throw "GetDP error";
} }
} }
void Message::Warning(const char *fmt, ...) void Message::Warning(const char *fmt, ...)
{ {
if(_verbosity < 2) return; if(_verbosity < 2) return;
char str[1024]; char str[1024];
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
vsnprintf(str, sizeof(str), fmt, args); vsnprintf(str, sizeof(str), fmt, args);
va_end(args); va_end(args);
if(_client){ if(_client) { _client->Warning(str); }
_client->Warning(str); else if(_onelabClient && _onelabClient->getName() != "GetDPServer") {
}
else if(_onelabClient && _onelabClient->getName() != "GetDPServer"){
_onelabClient->sendWarning(str); _onelabClient->sendWarning(str);
} }
else{ else {
const char *c0 = "", *c1 = ""; const char *c0 = "", *c1 = "";
if(!streamIsFile(stdout) && streamIsVT100(stdout)){ if(!streamIsFile(stdout) && streamIsVT100(stdout)) {
c0 = "\33[35m"; c1 = "\33[0m"; // magenta c0 = "\33[35m";
c1 = "\33[0m"; // magenta
} }
if(_commSize > 1) if(_commSize > 1)
fprintf(stdout, "%sWarning : [rank %3d] %s%s\n", c0, _commRank, str, c1); fprintf(stdout, "%sWarning : [rank %3d] %s%s\n", c0, _commRank, str, c1);
else else
fprintf(stdout, "%sWarning : %s%s\n", c0, str, c1); fprintf(stdout, "%sWarning : %s%s\n", c0, str, c1);
fflush(stdout); fflush(stdout);
} }
} }
void Message::Info(const char *fmt, ...) void Message::Info(const char *fmt, ...)
skipping to change at line 350 skipping to change at line 370
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
vsnprintf(str, sizeof(str), fmt, args); vsnprintf(str, sizeof(str), fmt, args);
va_end(args); va_end(args);
Info(4, str); Info(4, str);
} }
void Message::Info(int level, const char *fmt, ...) void Message::Info(int level, const char *fmt, ...)
{ {
if((_commRank && _isCommWorld && level > 0) || _verbosity < abs(level)) return if((_commRank && _isCommWorld && level > 0) || _verbosity < abs(level))
; return;
char str[1024]; char str[1024];
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
vsnprintf(str, sizeof(str), fmt, args); vsnprintf(str, sizeof(str), fmt, args);
va_end(args); va_end(args);
if(_infoCpu){ if(_infoCpu) {
Cpu(level, false, true, true, true, true, str); Cpu(level, false, true, true, true, true, str);
return; return;
} }
if(_client){ if(_client) { _client->Info(str); }
_client->Info(str); else if(_onelabClient && _onelabClient->getName() != "GetDPServer") {
}
else if(_onelabClient && _onelabClient->getName() != "GetDPServer"){
_onelabClient->sendInfo(str); _onelabClient->sendInfo(str);
} }
else{ else {
if(_isCommWorld && (_commSize == 1 || level > 0)) if(_isCommWorld && (_commSize == 1 || level > 0))
fprintf(stdout, "Info : %s\n", str); fprintf(stdout, "Info : %s\n", str);
else else
fprintf(stdout, "Info : [rank %3d] %s\n", _commRank, str); fprintf(stdout, "Info : [rank %3d] %s\n", _commRank, str);
fflush(stdout); fflush(stdout);
} }
} }
void Message::Direct(const char *fmt, ...) void Message::Direct(const char *fmt, ...)
{ {
skipping to change at line 392 skipping to change at line 411
va_start(args, fmt); va_start(args, fmt);
char str[1024]; char str[1024];
vsnprintf(str, sizeof(str), fmt, args); vsnprintf(str, sizeof(str), fmt, args);
va_end(args); va_end(args);
Direct(3, str); Direct(3, str);
} }
void Message::Direct(int level, const char *fmt, ...) void Message::Direct(int level, const char *fmt, ...)
{ {
if((_commRank && _isCommWorld && level > 0) || _verbosity < abs(level)) return if((_commRank && _isCommWorld && level > 0) || _verbosity < abs(level))
; return;
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
char str[1024]; char str[1024];
vsnprintf(str, sizeof(str), fmt, args); vsnprintf(str, sizeof(str), fmt, args);
va_end(args); va_end(args);
if(_client){ if(_client) { _client->Info(str); }
_client->Info(str); else if(_onelabClient && _onelabClient->getName() != "GetDPServer") {
}
else if(_onelabClient && _onelabClient->getName() != "GetDPServer"){
_onelabClient->sendInfo(str); _onelabClient->sendInfo(str);
} }
else{ else {
const char *c0 = "", *c1 = ""; const char *c0 = "", *c1 = "";
if(abs(level) == 3 && !streamIsFile(stdout) && streamIsVT100(stdout)){ if(abs(level) == 3 && !streamIsFile(stdout) && streamIsVT100(stdout)) {
c0 = "\33[34m"; c1 = "\33[0m"; // blue c0 = "\33[34m";
c1 = "\33[0m"; // blue
} }
if(_isCommWorld && (_commSize == 1 || level > 0)) if(_isCommWorld && (_commSize == 1 || level > 0))
fprintf(stdout, "%s%s%s\n", c0, str, c1); fprintf(stdout, "%s%s%s\n", c0, str, c1);
else else
fprintf(stdout, "%s[rank %3d] %s%s\n", c0, _commRank, str, c1); fprintf(stdout, "%s[rank %3d] %s%s\n", c0, _commRank, str, c1);
fflush(stdout); fflush(stdout);
} }
} }
void Message::Check(const char *fmt, ...) void Message::Check(const char *fmt, ...)
{ {
static std::string buffer; static std::string buffer;
if(_commRank && _isCommWorld) return; if(_commRank && _isCommWorld) return;
char str[5000]; char str[5000];
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
vsnprintf(str, sizeof(str), fmt, args); vsnprintf(str, sizeof(str), fmt, args);
va_end(args); va_end(args);
if(_client){ if(_client) { _client->Info(str); }
_client->Info(str); else if(_onelabClient && _onelabClient->getName() != "GetDPServer") {
}
else if(_onelabClient && _onelabClient->getName() != "GetDPServer"){
buffer += str; buffer += str;
bool found = false; bool found = false;
std::string::size_type idx = 0; std::string::size_type idx = 0;
while(1){ while(1) {
idx = buffer.find('\n'); idx = buffer.find('\n');
if(idx == std::string::npos) break; if(idx == std::string::npos) break;
found = true; found = true;
buffer.replace(idx, 1, " "); buffer.replace(idx, 1, " ");
idx++; idx++;
} }
if(found){ if(found) {
_onelabClient->sendInfo(buffer); _onelabClient->sendInfo(buffer);
buffer.clear(); buffer.clear();
} }
} }
else{ else {
fprintf(stdout, "%s", str); fprintf(stdout, "%s", str);
fflush(stdout); fflush(stdout);
} }
} }
void Message::Debug(const char *fmt, ...) void Message::Debug(const char *fmt, ...)
{ {
if(_verbosity < 99) return; if(_verbosity < 99) return;
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
char str[1024]; char str[1024];
vsnprintf(str, sizeof(str), fmt, args); vsnprintf(str, sizeof(str), fmt, args);
va_end(args); va_end(args);
if(_client){ if(_client) { _client->Info(str); }
_client->Info(str); else if(_onelabClient && _onelabClient->getName() != "GetDPServer") {
}
else if(_onelabClient && _onelabClient->getName() != "GetDPServer"){
_onelabClient->sendInfo(str); _onelabClient->sendInfo(str);
} }
else{ else {
if(_commSize > 1) if(_commSize > 1)
fprintf(stdout, "Debug : [rank %3d] %s\n", _commRank, str); fprintf(stdout, "Debug : [rank %3d] %s\n", _commRank, str);
else else
fprintf(stdout, "Debug : %s\n", str); fprintf(stdout, "Debug : %s\n", str);
fflush(stdout); fflush(stdout);
} }
} }
double Message::GetWallClockTime() double Message::GetWallClockTime() { return GetTimeOfDay() - _startTime; }
{
return GetTimeOfDay() - _startTime;
}
void Message::Cpu(const char *fmt, ...) void Message::Cpu(const char *fmt, ...)
{ {
if(_verbosity < 5) return; if(_verbosity < 5) return;
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
char str[1024]; char str[1024];
vsnprintf(str, sizeof(str), fmt, args); vsnprintf(str, sizeof(str), fmt, args);
va_end(args); va_end(args);
skipping to change at line 509 skipping to change at line 521
double s = 0.; double s = 0.;
long mem = 0; long mem = 0;
GetResources(&s, &mem); GetResources(&s, &mem);
double val[2] = {s, (double)mem / 1024. / 1024.}; double val[2] = {s, (double)mem / 1024. / 1024.};
double min[2] = {val[0], val[1]}; double min[2] = {val[0], val[1]};
double max[2] = {val[0], val[1]}; double max[2] = {val[0], val[1]};
double sum[2] = {val[0], val[1]}; double sum[2] = {val[0], val[1]};
#if defined(HAVE_PETSC) #if defined(HAVE_PETSC)
if(_commSize > 1 && _isCommWorld){ if(_commSize > 1 && _isCommWorld) {
MPI_Reduce(val, min, 2, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); MPI_Reduce(val, min, 2, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD);
MPI_Reduce(val, max, 2, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); MPI_Reduce(val, max, 2, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
MPI_Reduce(val, sum, 2, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); MPI_Reduce(val, sum, 2, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
} }
#endif #endif
if(_commRank && _isCommWorld && level > 0) return; if(_commRank && _isCommWorld && level > 0) return;
if(!mem) printMem = false; if(!mem) printMem = false;
onelab::remoteNetworkClient *remote = 0; onelab::remoteNetworkClient *remote = 0;
if(_onelabClient){ if(_onelabClient) {
remote = dynamic_cast<onelab::remoteNetworkClient*>(_onelabClient); remote = dynamic_cast<onelab::remoteNetworkClient *>(_onelabClient);
if(!remote || !remote->getGmshClient()) if(!remote || !remote->getGmshClient()) printTraffic = false;
printTraffic = false;
} }
else{ else {
printTraffic = false; printTraffic = false;
} }
char str[1024]; char str[1024];
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
vsnprintf(str, sizeof(str), fmt, args); vsnprintf(str, sizeof(str), fmt, args);
va_end(args); va_end(args);
if(strlen(fmt)) strcat(str, " "); if(strlen(fmt)) strcat(str, " ");
std::string pdate = ""; std::string pdate = "";
if(printDate){ if(printDate) {
time_t now; time_t now;
time(&now); time(&now);
pdate = ctime(&now); pdate = ctime(&now);
pdate.resize(pdate.size() - 1); pdate.resize(pdate.size() - 1);
if(printWallTime || printCpu || printMem || printTraffic) if(printWallTime || printCpu || printMem || printTraffic) pdate += ", ";
pdate += ", ";
} }
std::string pwall = ""; std::string pwall = "";
if(printWallTime){ if(printWallTime) {
char tmp[128]; char tmp[128];
sprintf(tmp, "Wall = %gs", GetWallClockTime()); sprintf(tmp, "Wall = %gs", GetWallClockTime());
pwall = tmp; pwall = tmp;
if(printCpu || printMem || printTraffic) if(printCpu || printMem || printTraffic) pwall += ", ";
pwall += ", ";
} }
std::string pcpu = ""; std::string pcpu = "";
if(printCpu){ if(printCpu) {
char tmp[128]; char tmp[128];
if(_commSize > 1 && _isCommWorld) if(_commSize > 1 && _isCommWorld)
sprintf(tmp, "CPU = %gs [%gs,%gs]", sum[0], min[0], max[0]); sprintf(tmp, "CPU = %gs [%gs,%gs]", sum[0], min[0], max[0]);
else else
sprintf(tmp, "CPU = %gs", max[0]); sprintf(tmp, "CPU = %gs", max[0]);
pcpu = tmp; pcpu = tmp;
if(printMem || printTraffic) if(printMem || printTraffic) pcpu += ", ";
pcpu += ", ";
} }
std::string pmem = ""; std::string pmem = "";
if(mem && printMem){ if(mem && printMem) {
char tmp[128]; char tmp[128];
if(_commSize > 1 && _isCommWorld) if(_commSize > 1 && _isCommWorld)
sprintf(tmp, "Mem = %gMb [%gMb,%gMb]", sum[1], min[1], max[1]); sprintf(tmp, "Mem = %gMb [%gMb,%gMb]", sum[1], min[1], max[1]);
else else
sprintf(tmp, "Mem = %gMb", max[1]); sprintf(tmp, "Mem = %gMb", max[1]);
pmem = tmp; pmem = tmp;
if(printTraffic) if(printTraffic) pmem += ", ";
pmem += ", ";
} }
std::string ptraffic = ""; std::string ptraffic = "";
if(printTraffic){ if(printTraffic) {
unsigned long int r = remote->getGmshClient()->ReceivedBytes(); unsigned long int r = remote->getGmshClient()->ReceivedBytes();
unsigned long int s = remote->getGmshClient()->SentBytes(); unsigned long int s = remote->getGmshClient()->SentBytes();
double rmb = (double)r / 1024. / 1024.; double rmb = (double)r / 1024. / 1024.;
double smb = (double)s / 1024. / 1024.; double smb = (double)s / 1024. / 1024.;
char tmp[128]; char tmp[128];
sprintf(tmp, "Recv/Send = %g/%gMb", rmb, smb); sprintf(tmp, "Recv/Send = %g/%gMb", rmb, smb);
ptraffic = tmp; ptraffic = tmp;
} }
char str2[256] = ""; char str2[256] = "";
if(pdate.size() || pwall.size() || pcpu.size() || pmem.size() || ptraffic.size if(pdate.size() || pwall.size() || pcpu.size() || pmem.size() ||
()) ptraffic.size())
sprintf(str2, "(%s%s%s%s%s)", pdate.c_str(), pwall.c_str(), pcpu.c_str(), sprintf(str2, "(%s%s%s%s%s)", pdate.c_str(), pwall.c_str(), pcpu.c_str(),
pmem.c_str(), ptraffic.c_str()); pmem.c_str(), ptraffic.c_str());
strcat(str, str2); strcat(str, str2);
if(_client){ if(_client) { _client->Info(str); }
_client->Info(str); else if(_onelabClient && _onelabClient->getName() != "GetDPServer") {
}
else if(_onelabClient && _onelabClient->getName() != "GetDPServer"){
_onelabClient->sendInfo(str); _onelabClient->sendInfo(str);
} }
else{ else {
if(_isCommWorld && (_commSize == 1 || level > 0)) if(_isCommWorld && (_commSize == 1 || level > 0))
fprintf(stdout, "Info : %s\n", str); fprintf(stdout, "Info : %s\n", str);
else else
fprintf(stdout, "Info : [rank %3d] %s\n", _commRank, str); fprintf(stdout, "Info : [rank %3d] %s\n", _commRank, str);
fflush(stdout); fflush(stdout);
} }
} }
void Message::ProgressMeter(int n, int N, const char *fmt, ...) void Message::ProgressMeter(int n, int N, const char *fmt, ...)
{ {
if((_commRank && _isCommWorld) || _verbosity < 4 || if((_commRank && _isCommWorld) || _verbosity < 4 || _progressMeterStep <= 0 ||
_progressMeterStep <= 0 || _progressMeterStep >= 100) return; _progressMeterStep >= 100)
return;
double percent = 100. * (double)n/(double)N;
if(N <= 0 || percent >= _progressMeterCurrent || n > N - 1){ double percent = 100. * (double)n / (double)N;
if(N <= 0 || percent >= _progressMeterCurrent || n > N - 1) {
char str[1024], str2[4096]; char str[1024], str2[4096];
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
vsnprintf(str, sizeof(str), fmt, args); vsnprintf(str, sizeof(str), fmt, args);
va_end(args); va_end(args);
sprintf(str2, "%3d%% : %s", _progressMeterCurrent, str); sprintf(str2, "%3d%% : %s", _progressMeterCurrent, str);
if(_onelabClient && _onelabClient->getName() == "GetDP"){ if(_onelabClient && _onelabClient->getName() == "GetDP") {
_onelabClient->sendProgress(str); _onelabClient->sendProgress(str);
} }
if(N <= 0){ if(N <= 0) {
if(_onelabClient && _onelabClient->getName() != "GetDPServer"){ if(_onelabClient && _onelabClient->getName() != "GetDPServer") {
onelab::number o(_onelabClient->getName() + "/Progress", n); onelab::number o(_onelabClient->getName() + "/Progress", n);
o.setLabel(std::string("GetDP ") + str); o.setLabel(std::string("GetDP ") + str);
o.setMin(0); o.setMin(0);
o.setMax(N); o.setMax(N);
o.setVisible(false); o.setVisible(false);
o.setReadOnly(true); o.setReadOnly(true);
_onelabClient->set(o); _onelabClient->set(o);
} }
return; return;
} }
if(_client){ if(_client) { _client->Progress(str2); }
_client->Progress(str2); else if(_onelabClient && _onelabClient->getName() != "GetDPServer") {
}
else if(_onelabClient && _onelabClient->getName() != "GetDPServer"){
onelab::number o(_onelabClient->getName() + "/Progress", onelab::number o(_onelabClient->getName() + "/Progress",
(n > N - 1) ? 0 : n); (n > N - 1) ? 0 : n);
o.setLabel(std::string("GetDP ") + str); o.setLabel(std::string("GetDP ") + str);
o.setMin(0); o.setMin(0);
o.setMax(N); o.setMax(N);
o.setVisible(false); o.setVisible(false);
o.setReadOnly(true); o.setReadOnly(true);
_onelabClient->set(o); _onelabClient->set(o);
} }
else if(!streamIsFile(stdout)){ else if(!streamIsFile(stdout)) {
fprintf(stdout, "%s \r", fprintf(stdout, "%s \r",
(n > N - 1) ? "" : str2); (n > N - 1) ? "" : str2);
fflush(stdout); fflush(stdout);
} }
while(_progressMeterCurrent < percent) while(_progressMeterCurrent < percent)
_progressMeterCurrent += _progressMeterStep; _progressMeterCurrent += _progressMeterStep;
} }
} }
void Message::PrintTimers() void Message::PrintTimers()
{ {
// do a single stdio call! // do a single stdio call!
std::string str; std::string str;
for(std::map<std::string, double>::iterator it = _timers.begin(); for(std::map<std::string, double>::iterator it = _timers.begin();
it != _timers.end(); it++){ it != _timers.end(); it++) {
if(it != _timers.begin()) str += ", "; if(it != _timers.begin()) str += ", ";
char tmp[256]; char tmp[256];
sprintf(tmp, "%s = %gs ", it->first.c_str(), it->second); sprintf(tmp, "%s = %gs ", it->first.c_str(), it->second);
str += std::string(tmp); str += std::string(tmp);
} }
if(!str.size()) return; if(!str.size()) return;
if(_client){ if(_client) { _client->Info((char *)str.c_str()); }
_client->Info((char*)str.c_str()); else if(_onelabClient && _onelabClient->getName() != "GetDPServer") {
}
else if(_onelabClient && _onelabClient->getName() != "GetDPServer"){
_onelabClient->sendInfo(str); _onelabClient->sendInfo(str);
} }
else{ else {
if(_commSize > 1) if(_commSize > 1)
fprintf(stdout, "Timers : [rank %3d] %s\n", _commRank, str.c_str()); fprintf(stdout, "Timers : [rank %3d] %s\n", _commRank, str.c_str());
else else
fprintf(stdout, "Timers : %s\n", str.c_str()); fprintf(stdout, "Timers : %s\n", str.c_str());
fflush(stdout); fflush(stdout);
} }
} }
void Message::PrintErrorCounter(const char *title) void Message::PrintErrorCounter(const char *title)
{ {
if(!_errorCount || _commRank || _verbosity < 1) return; if(!_errorCount || _commRank || _verbosity < 1) return;
Message::Error("%s encountered %d error%s - check the log for details", Message::Error("%s encountered %d error%s - check the log for details", title,
title, _errorCount, (_errorCount > 1) ? "s" : ""); _errorCount, (_errorCount > 1) ? "s" : "");
} }
void Message::InitializeSocket(std::string sockname) void Message::InitializeSocket(std::string sockname)
{ {
if(sockname.size()){ if(sockname.size()) {
_client = new GmshClient(); _client = new GmshClient();
if(_client->Connect(sockname.c_str()) < 0){ if(_client->Connect(sockname.c_str()) < 0) {
Message::Error("Could not connect to socket `%s'", sockname.c_str()); Message::Error("Could not connect to socket `%s'", sockname.c_str());
delete _client; delete _client;
_client = 0; _client = 0;
} }
else{ else {
_client->Start(); _client->Start();
} }
} }
} }
void Message::SendMergeFileRequest(const std::string &filename) void Message::SendMergeFileRequest(const std::string &filename)
{ {
if(_client){ if(_client) { _client->MergeFile((char *)filename.c_str()); }
_client->MergeFile((char*)filename.c_str()); else if(_onelabClient && _onelabClient->getName() != "GetDPServer") {
}
else if(_onelabClient && _onelabClient->getName() != "GetDPServer"){
_onelabClient->sendMergeFileRequest(filename); _onelabClient->sendMergeFileRequest(filename);
} }
} }
void Message::TestSocket() void Message::TestSocket()
{ {
if(_client){ if(_client) {
std::string tmp("View \"test\" {\n"); std::string tmp("View \"test\" {\n");
for(int i= 0; i < 1000000; i++) for(int i = 0; i < 1000000; i++) tmp += "ST(0,0,0, 1,0,0, 0,1,0){1,2,3};\n";
tmp += "ST(0,0,0, 1,0,0, 0,1,0){1,2,3};\n";
tmp += "};\n"; tmp += "};\n";
_client->SpeedTest(tmp.c_str()); _client->SpeedTest(tmp.c_str());
} }
} }
void Message::SendOptionOnSocket(int num, std::string option) void Message::SendOptionOnSocket(int num, std::string option)
{ {
if(_client){ if(_client) { _client->Option(num, option.c_str()); }
_client->Option(num, option.c_str());
}
} }
void Message::FinalizeSocket() void Message::FinalizeSocket()
{ {
if(_client){ if(_client) {
_client->Stop(); _client->Stop();
_client->Disconnect(); _client->Disconnect();
delete _client; delete _client;
_client = 0; _client = 0;
} }
} }
class localGetDP : public onelab::localClient { class localGetDP : public onelab::localClient {
public: public:
localGetDP() : onelab::localClient("GetDP") {} localGetDP() : onelab::localClient("GetDP") {}
#if defined(HAVE_GMSH) #if defined(HAVE_GMSH)
void sendMergeFileRequest(const std::string &name) void sendMergeFileRequest(const std::string &name)
{ {
GmshMergePostProcessingFile(name); GmshMergePostProcessingFile(name);
Msg::RequestRender(); Msg::RequestRender();
} }
void sendInfo(const std::string &msg){ Msg::Info("%s", msg.c_str()); } void sendInfo(const std::string &msg) { Msg::Info("%s", msg.c_str()); }
void sendWarning(const std::string &msg){ Msg::Warning("%s", msg.c_str()); } void sendWarning(const std::string &msg) { Msg::Warning("%s", msg.c_str()); }
void sendError(const std::string &msg){ Msg::Error("%s", msg.c_str()); } void sendError(const std::string &msg) { Msg::Error("%s", msg.c_str()); }
void sendProgress(const std::string &msg){ } void sendProgress(const std::string &msg) {}
#endif #endif
}; };
void Message::InitializeOnelab(std::string name, std::string sockname) void Message::InitializeOnelab(std::string name, std::string sockname)
{ {
if(sockname.size()){ if(sockname.size()) {
// getdp is called by a distant onelab server // getdp is called by a distant onelab server
onelab::remoteNetworkClient *c = new onelab::remoteNetworkClient(name, sockn onelab::remoteNetworkClient *c =
ame); new onelab::remoteNetworkClient(name, sockname);
if(!c->getGmshClient()){ if(!c->getGmshClient()) {
Message::Error("Could not connect to ONELAB server"); Message::Error("Could not connect to ONELAB server");
delete c; delete c;
} }
else{ else {
_onelabClient = c; _onelabClient = c;
// send configuration options (we send them even if Action != initialize), // send configuration options (we send them even if Action != initialize),
// so that they are also sent e.g. when the database is reset // so that they are also sent e.g. when the database is reset
onelab::string o(name + "/File extension", ".pro"); onelab::string o(name + "/File extension", ".pro");
o.setVisible(false); o.setVisible(false);
o.setAttribute("Persistent", "1"); o.setAttribute("Persistent", "1");
_onelabClient->set(o); _onelabClient->set(o);
onelab::number o2(name + "/Use command line", 1.); onelab::number o2(name + "/Use command line", 1.);
o2.setVisible(false); o2.setVisible(false);
o2.setAttribute("Persistent", "1"); o2.setAttribute("Persistent", "1");
_onelabClient->set(o2); _onelabClient->set(o2);
onelab::number o3(name + "/Guess model name", 1.); onelab::number o3(name + "/Guess model name", 1.);
o3.setVisible(false); o3.setVisible(false);
o3.setAttribute("Persistent", "1"); o3.setAttribute("Persistent", "1");
_onelabClient->set(o3); _onelabClient->set(o3);
std::vector<onelab::string> ps; std::vector<onelab::string> ps;
_onelabClient->get(ps, name + "/Action"); _onelabClient->get(ps, name + "/Action");
if(ps.size()){ if(ps.size()) {
Info("Performing ONELAB '%s'", ps[0].getValue().c_str()); Info("Performing ONELAB '%s'", ps[0].getValue().c_str());
if(ps[0].getValue() == "initialize") Exit(0); if(ps[0].getValue() == "initialize") Exit(0);
} }
} }
} }
else{ else {
if(name == "GetDP"){ if(name == "GetDP") {
// getdp is called within the same memory space as the server // getdp is called within the same memory space as the server
_onelabClient = new localGetDP(); _onelabClient = new localGetDP();
} }
else{ else {
// getdp is called without a connection to a onelab server, but with the // getdp is called without a connection to a onelab server, but with the
// name of a onelab database file; GetDP in this case becomes the onelab // name of a onelab database file; GetDP in this case becomes the onelab
// server // server
_onelabClient = new onelab::localClient("GetDPServer"); _onelabClient = new onelab::localClient("GetDPServer");
FILE *fp = FOpen(name.c_str(), "rb"); FILE *fp = FOpen(name.c_str(), "rb");
if(fp){ if(fp) {
Message::Info("Reading ONELAB database '%s'", name.c_str()); Message::Info("Reading ONELAB database '%s'", name.c_str());
_onelabClient->fromFile(fp); _onelabClient->fromFile(fp);
fclose(fp); fclose(fp);
} }
else else
Message::Error("Could not open file '%s'", name.c_str()); Message::Error("Could not open file '%s'", name.c_str());
} }
} }
} }
void Message::AddOnelabNumberChoice(std::string name, const std::vector<double> void Message::AddOnelabNumberChoice(std::string name,
&value, const std::vector<double> &value,
const char *color, const char *units, const char *color, const char *units,
const char *label, bool visible, bool closed const char *label, bool visible,
) bool closed)
{ {
if(_onelabClient){ if(_onelabClient) {
std::vector<onelab::number> ps; std::vector<onelab::number> ps;
// optimized exchange (without growing choice vector) // optimized exchange (without growing choice vector)
_onelabClient->getWithoutChoices(ps, name); _onelabClient->getWithoutChoices(ps, name);
if(ps.empty()){ if(ps.empty()) {
ps.resize(1); ps.resize(1);
ps[0].setName(name); ps[0].setName(name);
ps[0].setReadOnly(true); ps[0].setReadOnly(true);
} }
if(color) ps[0].setAttribute("Highlight", color); if(color) ps[0].setAttribute("Highlight", color);
if(units) ps[0].setAttribute("Units", units); if(units) ps[0].setAttribute("Units", units);
if(label) ps[0].setLabel(label); if(label) ps[0].setLabel(label);
ps[0].setAttribute("Closed", closed ? "1" : "0"); ps[0].setAttribute("Closed", closed ? "1" : "0");
ps[0].setValues(value); ps[0].setValues(value);
ps[0].setVisible(visible); ps[0].setVisible(visible);
skipping to change at line 861 skipping to change at line 861
o.setVisible(false); o.setVisible(false);
_onelabClient->set(o); _onelabClient->set(o);
#endif #endif
} }
} }
void Message::AddOnelabStringChoice(std::string name, std::string kind, void Message::AddOnelabStringChoice(std::string name, std::string kind,
std::string value, bool updateValue, std::string value, bool updateValue,
bool readOnly) bool readOnly)
{ {
if(_onelabClient){ if(_onelabClient) {
std::vector<std::string> choices; std::vector<std::string> choices;
std::vector<onelab::string> ps; std::vector<onelab::string> ps;
_onelabClient->get(ps, name); _onelabClient->get(ps, name);
if(ps.size()){ if(ps.size()) {
choices = ps[0].getChoices(); choices = ps[0].getChoices();
if(std::find(choices.begin(), choices.end(), value) == choices.end()) if(std::find(choices.begin(), choices.end(), value) == choices.end())
choices.push_back(value); choices.push_back(value);
if(updateValue) if(updateValue) ps[0].setValue(value);
ps[0].setValue(value);
} }
else{ else {
ps.resize(1); ps.resize(1);
ps[0].setName(name); ps[0].setName(name);
ps[0].setKind(kind); ps[0].setKind(kind);
ps[0].setValue(value); ps[0].setValue(value);
choices.push_back(value); choices.push_back(value);
} }
ps[0].setChoices(choices); ps[0].setChoices(choices);
if(readOnly){ if(readOnly) {
ps[0].setReadOnly(true); ps[0].setReadOnly(true);
ps[0].setAttribute("AutoCheck", "0"); ps[0].setAttribute("AutoCheck", "0");
} }
else{ else {
ps[0].setReadOnly(false); ps[0].setReadOnly(false);
ps[0].setAttribute("AutoCheck", "1"); ps[0].setAttribute("AutoCheck", "1");
} }
_onelabClient->set(ps[0]); _onelabClient->set(ps[0]);
} }
} }
void Message::SetOnelabNumber(std::string name, double val) void Message::SetOnelabNumber(std::string name, double val)
{ {
if(_onelabClient){ if(_onelabClient) {
std::vector<onelab::number> numbers; std::vector<onelab::number> numbers;
// get if first so we can keep its options // get if first so we can keep its options
_onelabClient->get(numbers, name); _onelabClient->get(numbers, name);
if(numbers.empty()){ if(numbers.empty()) {
numbers.resize(1); numbers.resize(1);
numbers[0].setName(name); numbers[0].setName(name);
} }
numbers[0].setValue(val); numbers[0].setValue(val);
_onelabClient->set(numbers[0]); _onelabClient->set(numbers[0]);
} }
} }
void Message::SetOnelabString(std::string name, std::string val) void Message::SetOnelabString(std::string name, std::string val)
{ {
if(_onelabClient){ if(_onelabClient) {
std::vector<onelab::string> strings; std::vector<onelab::string> strings;
_onelabClient->get(strings, name); _onelabClient->get(strings, name);
if(strings.empty()){ if(strings.empty()) {
strings.resize(1); strings.resize(1);
strings[0].setName(name); strings[0].setName(name);
} }
strings[0].setValue(val); strings[0].setValue(val);
_onelabClient->set(strings[0]); _onelabClient->set(strings[0]);
} }
} }
double Message::GetOnelabNumber(std::string name, double defaultValue, double Message::GetOnelabNumber(std::string name, double defaultValue,
bool errorIfMissing) bool errorIfMissing)
{ {
if(_onelabClient){ if(_onelabClient) {
std::vector<onelab::number> numbers; std::vector<onelab::number> numbers;
_onelabClient->get(numbers, name); _onelabClient->get(numbers, name);
if(numbers.empty()){ if(numbers.empty()) {
if(errorIfMissing) if(errorIfMissing)
Message::Error("Unknown ONELAB number parameter '%s'", name.c_str()); Message::Error("Unknown ONELAB number parameter '%s'", name.c_str());
return defaultValue; return defaultValue;
} }
else else
return numbers[0].getValue(); return numbers[0].getValue();
} }
if(errorIfMissing) if(errorIfMissing) Message::Warning("GetNumber requires a ONELAB client");
Message::Warning("GetNumber requires a ONELAB client");
return defaultValue; return defaultValue;
} }
void Message::GetOnelabNumbers(std::string name, std::vector<double> &value, void Message::GetOnelabNumbers(std::string name, std::vector<double> &value,
bool errorIfMissing) bool errorIfMissing)
{ {
if(_onelabClient){ if(_onelabClient) {
std::vector<onelab::number> numbers; std::vector<onelab::number> numbers;
_onelabClient->get(numbers, name); _onelabClient->get(numbers, name);
if(numbers.empty()){ if(numbers.empty()) {
if(errorIfMissing) if(errorIfMissing)
Message::Error("Unknown ONELAB number parameter '%s'", name.c_str()); Message::Error("Unknown ONELAB number parameter '%s'", name.c_str());
} }
else else
value = numbers[0].getValues(); value = numbers[0].getValues();
} }
if(errorIfMissing) if(errorIfMissing) Message::Warning("GetNumber requires a ONELAB client");
Message::Warning("GetNumber requires a ONELAB client");
} }
std::string Message::GetOnelabString(std::string name, const std::string &defaul std::string Message::GetOnelabString(std::string name,
tValue, const std::string &defaultValue,
bool errorIfMissing) bool errorIfMissing)
{ {
if(_onelabClient){ if(_onelabClient) {
std::vector<onelab::string> ps; std::vector<onelab::string> ps;
_onelabClient->get(ps, name); _onelabClient->get(ps, name);
if(ps.empty()){ if(ps.empty()) {
if(errorIfMissing) if(errorIfMissing)
Message::Error("Unknown ONELAB string parameter '%s'", name.c_str()); Message::Error("Unknown ONELAB string parameter '%s'", name.c_str());
return defaultValue; return defaultValue;
} }
else{ else {
return ps[0].getValue(); return ps[0].getValue();
} }
} }
if(errorIfMissing) if(errorIfMissing) Message::Warning("GetString requires a ONELAB client");
Message::Warning("GetString requires a ONELAB client");
return defaultValue; return defaultValue;
} }
std::string Message::GetOnelabAction() std::string Message::GetOnelabAction()
{ {
if(_onelabClient){ if(_onelabClient) {
std::vector<onelab::string> ps; std::vector<onelab::string> ps;
_onelabClient->get(ps, _onelabClient->getName() + "/Action"); _onelabClient->get(ps, _onelabClient->getName() + "/Action");
if(ps.size()) return ps[0].getValue(); if(ps.size()) return ps[0].getValue();
} }
return ""; return "";
} }
std::string Message::GetOnelabClientName() std::string Message::GetOnelabClientName()
{ {
if(_onelabClient) return _onelabClient->getName(); if(_onelabClient) return _onelabClient->getName();
return ""; return "";
} }
static std::string _getParameterName(char *Name, Message::cmap &copt) static std::string _getParameterName(char *Name, Message::cmap &copt)
{ {
std::string name(Name); std::string name(Name);
if(copt.count("Path")){ if(copt.count("Path")) {
std::string path = copt["Path"][0]; std::string path = copt["Path"][0];
// if path ends with a number, assume it's for ordering purposes // if path ends with a number, assume it's for ordering purposes
if(path.size() && path[path.size() - 1] >= '0' && path[path.size() - 1] <= ' if(path.size() && path[path.size() - 1] >= '0' &&
9') path[path.size() - 1] <= '9')
name = path + name; name = path + name;
else if(path.size() && path[path.size() - 1] == '/') else if(path.size() && path[path.size() - 1] == '/')
name = path + name; name = path + name;
else else
name = path + "/" + name; name = path + "/" + name;
} }
return name; return name;
} }
static void _setStandardOptions(onelab::parameter *p, Message::fmap &fopt, static void _setStandardOptions(onelab::parameter *p, Message::fmap &fopt,
Message::cmap &copt) Message::cmap &copt)
{ {
// strings // strings
if(copt.count("Label")) p->setLabel(copt["Label"][0]); if(copt.count("Label")) p->setLabel(copt["Label"][0]);
if(copt.count("ShortHelp")) // for backward compatibility if(copt.count("ShortHelp")) // for backward compatibility
p->setLabel(copt["ShortHelp"][0]); p->setLabel(copt["ShortHelp"][0]);
if(copt.count("Help")) p->setHelp(copt["Help"][0]); if(copt.count("Help")) p->setHelp(copt["Help"][0]);
if(copt.count("Highlight")) p->setAttribute("Highlight", copt["Highlight"][0]) if(copt.count("Highlight"))
; p->setAttribute("Highlight", copt["Highlight"][0]);
if(copt.count("Macro")) p->setAttribute("Macro", copt["Macro"][0]); if(copt.count("Macro")) p->setAttribute("Macro", copt["Macro"][0]);
if(copt.count("GmshOption")) p->setAttribute("GmshOption", copt["GmshOption"][ if(copt.count("GmshOption"))
0]); p->setAttribute("GmshOption", copt["GmshOption"][0]);
if(copt.count("ServerAction")) p->setAttribute("ServerAction", copt["ServerAct if(copt.count("ServerAction"))
ion"][0]); p->setAttribute("ServerAction", copt["ServerAction"][0]);
if(copt.count("Units")) p->setAttribute("Units", copt["Units"][0]); if(copt.count("Units")) p->setAttribute("Units", copt["Units"][0]);
if(copt.count("AutoCheck")) // for backward compatibility if(copt.count("AutoCheck")) // for backward compatibility
p->setAttribute("AutoCheck", copt["AutoCheck"][0]); p->setAttribute("AutoCheck", copt["AutoCheck"][0]);
// numbers // numbers
if(fopt.count("Visible")) p->setVisible(fopt["Visible"][0] ? true : false); if(fopt.count("Visible")) p->setVisible(fopt["Visible"][0] ? true : false);
if(fopt.count("ReadOnly")) p->setReadOnly(fopt["ReadOnly"][0] ? true : false); if(fopt.count("ReadOnly")) p->setReadOnly(fopt["ReadOnly"][0] ? true : false);
if(fopt.count("NeverChanged")) p->setNeverChanged(fopt["NeverChanged"][0] ? tr if(fopt.count("NeverChanged"))
ue : false); p->setNeverChanged(fopt["NeverChanged"][0] ? true : false);
if(fopt.count("ChangedValue")) p->setChangedValue(fopt["ChangedValue"][0]); if(fopt.count("ChangedValue")) p->setChangedValue(fopt["ChangedValue"][0]);
if(fopt.count("ReadOnlyRange")) if(fopt.count("ReadOnlyRange"))
p->setAttribute("ReadOnlyRange", fopt["ReadOnlyRange"][0] ? "1" : "0"); p->setAttribute("ReadOnlyRange", fopt["ReadOnlyRange"][0] ? "1" : "0");
if(fopt.count("AutoCheck")) if(fopt.count("AutoCheck"))
p->setAttribute("AutoCheck", fopt["AutoCheck"][0] ? "1" : "0"); p->setAttribute("AutoCheck", fopt["AutoCheck"][0] ? "1" : "0");
} }
void Message::ExchangeOnelabParameter(Constant *c, fmap &fopt, cmap &copt) void Message::ExchangeOnelabParameter(Constant *c, fmap &fopt, cmap &copt)
{ {
if(!_onelabClient) return; if(!_onelabClient) return;
std::string name; std::string name;
if(copt.count("Name")) if(copt.count("Name")) name = copt["Name"][0];
name = copt["Name"][0];
if(name.empty()){ if(name.empty()) {
if(copt.size() || fopt.size()) if(copt.size() || fopt.size())
Message::Error("From now on you need to use the `Name' attribute to create Message::Error(
a " "From now on you need to use the `Name' attribute to create a "
"ONELAB parameter: `Name \"%s\"'", "ONELAB parameter: `Name \"%s\"'",
_getParameterName(c->Name, copt).c_str()); _getParameterName(c->Name, copt).c_str());
return; return;
} }
if(c->Type == VAR_FLOAT || c->Type == VAR_LISTOFFLOAT){ if(c->Type == VAR_FLOAT || c->Type == VAR_LISTOFFLOAT) {
std::vector<onelab::number> ps; std::vector<onelab::number> ps;
_onelabClient->get(ps, name); _onelabClient->get(ps, name);
bool noRange = true, noChoices = true, noLoop = true; bool noRange = true, noChoices = true, noLoop = true;
bool noGraph = true, noClosed = true; bool noGraph = true, noClosed = true;
if(ps.size()){ if(ps.size()) {
bool useLocalValue = ps[0].getReadOnly(); bool useLocalValue = ps[0].getReadOnly();
if(fopt.count("ReadOnly")) useLocalValue = fopt["ReadOnly"][0]; if(fopt.count("ReadOnly")) useLocalValue = fopt["ReadOnly"][0];
if(useLocalValue){ if(useLocalValue) {
if(c->Type == VAR_FLOAT){ if(c->Type == VAR_FLOAT) { ps[0].setValue(c->Value.Float); }
ps[0].setValue(c->Value.Float); else {
}
else{
std::vector<double> in; std::vector<double> in;
for(int i = 0; i < List_Nbr(c->Value.List); i++){ for(int i = 0; i < List_Nbr(c->Value.List); i++) {
double d; double d;
List_Read(c->Value.List, i, &d); List_Read(c->Value.List, i, &d);
in.push_back(d); in.push_back(d);
} }
ps[0].setValues(in); ps[0].setValues(in);
} }
} }
else{ // use value from server else { // use value from server
if(c->Type == VAR_FLOAT){ if(c->Type == VAR_FLOAT) { c->Value.Float = ps[0].getValue(); }
c->Value.Float = ps[0].getValue(); else {
}
else{
List_Reset(c->Value.List); List_Reset(c->Value.List);
for(unsigned int i = 0; i < ps[0].getValues().size(); i++){ for(unsigned int i = 0; i < ps[0].getValues().size(); i++) {
double d = ps[0].getValues()[i]; double d = ps[0].getValues()[i];
List_Add(c->Value.List, &d); List_Add(c->Value.List, &d);
} }
} }
} }
// keep track of these attributes, which can be changed server-side // keep track of these attributes, which can be changed server-side
// (unless they are not visible, or, for the range/choices, when // (unless they are not visible, or, for the range/choices, when
// explicitely setting these attributes as ReadOnly) // explicitely setting these attributes as ReadOnly)
if(ps[0].getVisible()){ if(ps[0].getVisible()) {
if(!(fopt.count("ReadOnlyRange") && fopt["ReadOnlyRange"][0])){ if(!(fopt.count("ReadOnlyRange") && fopt["ReadOnlyRange"][0])) {
if(ps[0].getMin() != -onelab::parameter::maxNumber() || if(ps[0].getMin() != -onelab::parameter::maxNumber() ||
ps[0].getMax() != onelab::parameter::maxNumber() || ps[0].getMax() != onelab::parameter::maxNumber() ||
ps[0].getStep() != 0.) noRange = false; ps[0].getStep() != 0.)
noRange = false;
if(ps[0].getChoices().size()) noChoices = false; if(ps[0].getChoices().size()) noChoices = false;
} }
if(ps[0].getAttribute("Loop").size()) noLoop = false; if(ps[0].getAttribute("Loop").size()) noLoop = false;
if(ps[0].getAttribute("Graph").size()) noGraph = false; if(ps[0].getAttribute("Graph").size()) noGraph = false;
if(ps[0].getAttribute("Closed").size()) noClosed = false; if(ps[0].getAttribute("Closed").size()) noClosed = false;
} }
} }
else{ else {
ps.resize(1); ps.resize(1);
ps[0].setName(name); ps[0].setName(name);
if(c->Type == VAR_FLOAT){ if(c->Type == VAR_FLOAT) { ps[0].setValue(c->Value.Float); }
ps[0].setValue(c->Value.Float); else {
}
else{
std::vector<double> in; std::vector<double> in;
for(int i = 0; i < List_Nbr(c->Value.List); i++){ for(int i = 0; i < List_Nbr(c->Value.List); i++) {
double d; double d;
List_Read(c->Value.List, i, &d); List_Read(c->Value.List, i, &d);
in.push_back(d); in.push_back(d);
} }
ps[0].setValues(in); ps[0].setValues(in);
} }
} }
// send updated parameter to server // send updated parameter to server
if(noRange && fopt.count("Range") && fopt["Range"].size() == 2){ if(noRange && fopt.count("Range") && fopt["Range"].size() == 2) {
ps[0].setMin(fopt["Range"][0]); ps[0].setMax(fopt["Range"][1]); ps[0].setMin(fopt["Range"][0]);
} ps[0].setMax(fopt["Range"][1]);
else if(noRange && fopt.count("Min") && fopt.count("Max")){ }
ps[0].setMin(fopt["Min"][0]); ps[0].setMax(fopt["Max"][0]); else if(noRange && fopt.count("Min") && fopt.count("Max")) {
} ps[0].setMin(fopt["Min"][0]);
else if(noRange && fopt.count("Min")){ ps[0].setMax(fopt["Max"][0]);
ps[0].setMin(fopt["Min"][0]); ps[0].setMax(onelab::parameter::maxNumber()) }
; else if(noRange && fopt.count("Min")) {
} ps[0].setMin(fopt["Min"][0]);
else if(noRange && fopt.count("Max")){ ps[0].setMax(onelab::parameter::maxNumber());
ps[0].setMax(fopt["Max"][0]); ps[0].setMin(-onelab::parameter::maxNumber() }
); else if(noRange && fopt.count("Max")) {
ps[0].setMax(fopt["Max"][0]);
ps[0].setMin(-onelab::parameter::maxNumber());
} }
if(noRange && fopt.count("Step")) ps[0].setStep(fopt["Step"][0]); if(noRange && fopt.count("Step")) ps[0].setStep(fopt["Step"][0]);
// if no range/min/max/step info is provided, try to compute a reasonnable // if no range/min/max/step info is provided, try to compute a reasonnable
// range and step (this makes the gui much nicer to use) // range and step (this makes the gui much nicer to use)
if(c->Type == VAR_FLOAT && noRange && !fopt.count("Range") && if(c->Type == VAR_FLOAT && noRange && !fopt.count("Range") &&
!fopt.count("Step") && !fopt.count("Min") && !fopt.count("Max")){ !fopt.count("Step") && !fopt.count("Min") && !fopt.count("Max")) {
bool isInteger = (floor(c->Value.Float) == c->Value.Float); bool isInteger = (floor(c->Value.Float) == c->Value.Float);
double fact = isInteger ? 10. : 100.; double fact = isInteger ? 10. : 100.;
if(c->Value.Float > 0){ if(c->Value.Float > 0) {
ps[0].setMin(c->Value.Float / fact); ps[0].setMin(c->Value.Float / fact);
ps[0].setMax(c->Value.Float * fact); ps[0].setMax(c->Value.Float * fact);
ps[0].setStep((ps[0].getMax() - ps[0].getMin()) / 100.); ps[0].setStep((ps[0].getMax() - ps[0].getMin()) / 100.);
} }
else if(c->Value.Float < 0){ else if(c->Value.Float < 0) {
ps[0].setMin(c->Value.Float * fact); ps[0].setMin(c->Value.Float * fact);
ps[0].setMax(c->Value.Float / fact); ps[0].setMax(c->Value.Float / fact);
ps[0].setStep((ps[0].getMax() - ps[0].getMin()) / 100.); ps[0].setStep((ps[0].getMax() - ps[0].getMin()) / 100.);
} }
if(c->Value.Float && isInteger){ if(c->Value.Float && isInteger) {
ps[0].setMin((int)ps[0].getMin()); ps[0].setMin((int)ps[0].getMin());
ps[0].setMax((int)ps[0].getMax()); ps[0].setMax((int)ps[0].getMax());
ps[0].setStep((int)ps[0].getStep()); ps[0].setStep((int)ps[0].getStep());
} }
} }
if(noChoices && fopt.count("Choices")){ if(noChoices && fopt.count("Choices")) {
ps[0].setChoices(fopt["Choices"]); ps[0].setChoices(fopt["Choices"]);
if(copt.count("Choices")) ps[0].setChoiceLabels(copt["Choices"]); if(copt.count("Choices")) ps[0].setChoiceLabels(copt["Choices"]);
} }
if(noLoop && copt.count("Loop")) // for backward compatibility if(noLoop && copt.count("Loop")) // for backward compatibility
ps[0].setAttribute("Loop", copt["Loop"][0]); ps[0].setAttribute("Loop", copt["Loop"][0]);
if(noLoop && fopt.count("Loop")) if(noLoop && fopt.count("Loop"))
ps[0].setAttribute("Loop", (fopt["Loop"][0] == 3.) ? "3" : ps[0].setAttribute("Loop", (fopt["Loop"][0] == 3.) ? "3" :
(fopt["Loop"][0] == 2.) ? "2" : (fopt["Loop"][0] == 2.) ? "2" :
(fopt["Loop"][0] == 1.) ? "1" : ""); (fopt["Loop"][0] == 1.) ? "1" :
if(noGraph && copt.count("Graph")) ps[0].setAttribute("Graph", copt["Graph"] "");
[0]); if(noGraph && copt.count("Graph"))
ps[0].setAttribute("Graph", copt["Graph"][0]);
if(noClosed && copt.count("Closed")) // for backward compatibility if(noClosed && copt.count("Closed")) // for backward compatibility
ps[0].setAttribute("Closed", copt["Closed"][0]); ps[0].setAttribute("Closed", copt["Closed"][0]);
if(noClosed && fopt.count("Closed")) if(noClosed && fopt.count("Closed"))
ps[0].setAttribute("Closed", fopt["Closed"][0] ? "1" : "0"); ps[0].setAttribute("Closed", fopt["Closed"][0] ? "1" : "0");
if(copt.count("NumberFormat")) if(copt.count("NumberFormat"))
ps[0].setAttribute("NumberFormat", copt["NumberFormat"][0]); ps[0].setAttribute("NumberFormat", copt["NumberFormat"][0]);
_setStandardOptions(&ps[0], fopt, copt); _setStandardOptions(&ps[0], fopt, copt);
_onelabClient->set(ps[0]); _onelabClient->set(ps[0]);
} }
else if(c->Type == VAR_CHAR){ else if(c->Type == VAR_CHAR) {
std::vector<onelab::string> ps; std::vector<onelab::string> ps;
_onelabClient->get(ps, name); _onelabClient->get(ps, name);
bool noClosed = true, noMultipleSelection = true; bool noClosed = true, noMultipleSelection = true;
if(ps.size()){ if(ps.size()) {
bool useLocalValue = ps[0].getReadOnly(); bool useLocalValue = ps[0].getReadOnly();
if(fopt.count("ReadOnly")) useLocalValue = fopt["ReadOnly"][0]; if(fopt.count("ReadOnly")) useLocalValue = fopt["ReadOnly"][0];
if(useLocalValue) if(useLocalValue)
ps[0].setValue(c->Value.Char); // use local value ps[0].setValue(c->Value.Char); // use local value
else else
c->Value.Char = strSave(ps[0].getValue().c_str()); // use value from serv c->Value.Char =
er strSave(ps[0].getValue().c_str()); // use value from server
// keep track of these attributes, which can be changed server-side // keep track of these attributes, which can be changed server-side
// (unless they are not visible) // (unless they are not visible)
if(ps[0].getVisible()){ if(ps[0].getVisible()) {
if(ps[0].getAttribute("Closed").size()) noClosed = false; if(ps[0].getAttribute("Closed").size()) noClosed = false;
if(ps[0].getAttribute("MultipleSelection").size()) noMultipleSelection = if(ps[0].getAttribute("MultipleSelection").size())
false; noMultipleSelection = false;
} }
} }
else{ else {
ps.resize(1); ps.resize(1);
ps[0].setName(name); ps[0].setName(name);
ps[0].setValue(c->Value.Char); ps[0].setValue(c->Value.Char);
} }
// send updated parameter to server // send updated parameter to server
if(copt.count("Kind")) ps[0].setKind(copt["Kind"][0]); if(copt.count("Kind")) ps[0].setKind(copt["Kind"][0]);
if(copt.count("Choices")) ps[0].setChoices(copt["Choices"]); if(copt.count("Choices")) ps[0].setChoices(copt["Choices"]);
if(noClosed && copt.count("Closed")) // for backward compatibility if(noClosed && copt.count("Closed")) // for backward compatibility
ps[0].setAttribute("Closed", copt["Closed"][0]); ps[0].setAttribute("Closed", copt["Closed"][0]);
if(noClosed && fopt.count("Closed")) // for backward compatibility if(noClosed && fopt.count("Closed")) // for backward compatibility
skipping to change at line 1220 skipping to change at line 1225
extern void Fill_GroupInitialListFromString(List_T *list, const char *str); extern void Fill_GroupInitialListFromString(List_T *list, const char *str);
void Message::UndefineOnelabParameter(const std::string &name) void Message::UndefineOnelabParameter(const std::string &name)
{ {
if(!_onelabClient) return; if(!_onelabClient) return;
_onelabClient->clear(name); _onelabClient->clear(name);
} }
void Message::FinalizeOnelab() void Message::FinalizeOnelab()
{ {
if(_onelabClient){ if(_onelabClient) {
// add default computation modes // add default computation modes
std::string name = _onelabClient->getName(); std::string name = _onelabClient->getName();
std::vector<onelab::string> ps; std::vector<onelab::string> ps;
_onelabClient->get(ps, name + "/Action"); _onelabClient->get(ps, name + "/Action");
if(ps.size()){ if(ps.size()) {
if(ps[0].getValue() != "initialize"){ if(ps[0].getValue() != "initialize") {
// Compute commands // Compute commands
_onelabClient->get(ps, name + "/9ComputeCommand"); _onelabClient->get(ps, name + "/9ComputeCommand");
if(ps.empty()){ // only change value if none exists if(ps.empty()) { // only change value if none exists
ps.resize(1); ps.resize(1);
ps[0].setName(name + "/9ComputeCommand"); ps[0].setName(name + "/9ComputeCommand");
ps[0].setValue("-solve -pos"); ps[0].setValue("-solve -pos");
} }
ps[0].setLabel("Compute command"); ps[0].setLabel("Compute command");
std::vector<std::string> choices; std::vector<std::string> choices;
choices.push_back("-pre"); choices.push_back("-pre");
choices.push_back("-cal"); choices.push_back("-cal");
choices.push_back("-pos"); choices.push_back("-pos");
choices.push_back("-solve"); choices.push_back("-solve");
choices.push_back("-solve -pos"); choices.push_back("-solve -pos");
ps[0].setChoices(choices); ps[0].setChoices(choices);
_onelabClient->set(ps[0]); _onelabClient->set(ps[0]);
// Model checking // Model checking
std::vector<onelab::number> pn; std::vector<onelab::number> pn;
_onelabClient->get(pn, name + "/}ModelCheck"); _onelabClient->get(pn, name + "/}ModelCheck");
if(pn.empty()){ // only change value if none exists if(pn.empty()) { // only change value if none exists
pn.resize(1); pn.resize(1);
pn[0].setName(name + "/}ModelCheck"); pn[0].setName(name + "/}ModelCheck");
pn[0].setValue(0); pn[0].setValue(0);
} }
if(pn[0].getVisible()){ if(pn[0].getVisible()) {
pn[0].setLabel("Model check"); pn[0].setLabel("Model check");
std::vector<double> nchoices; std::vector<double> nchoices;
std::vector<std::string> labels; std::vector<std::string> labels;
nchoices.push_back(0); labels.push_back("None"); nchoices.push_back(0);
nchoices.push_back(1); labels.push_back("Constants"); labels.push_back("None");
nchoices.push_back(2); labels.push_back("Groups"); nchoices.push_back(1);
nchoices.push_back(3); labels.push_back("Functions"); labels.push_back("Constants");
nchoices.push_back(4); labels.push_back("Constraints"); nchoices.push_back(2);
nchoices.push_back(5); labels.push_back("Jacobians"); labels.push_back("Groups");
nchoices.push_back(6); labels.push_back("Integrations"); nchoices.push_back(3);
nchoices.push_back(7); labels.push_back("FunctionSpaces"); labels.push_back("Functions");
nchoices.push_back(8); labels.push_back("Formulations"); nchoices.push_back(4);
nchoices.push_back(9); labels.push_back("Resolutions"); labels.push_back("Constraints");
nchoices.push_back(10); labels.push_back("PostProcessings"); nchoices.push_back(5);
nchoices.push_back(11); labels.push_back("PostOperations"); labels.push_back("Jacobians");
nchoices.push_back(6);
labels.push_back("Integrations");
nchoices.push_back(7);
labels.push_back("FunctionSpaces");
nchoices.push_back(8);
labels.push_back("Formulations");
nchoices.push_back(9);
labels.push_back("Resolutions");
nchoices.push_back(10);
labels.push_back("PostProcessings");
nchoices.push_back(11);
labels.push_back("PostOperations");
pn[0].setChoices(nchoices); pn[0].setChoices(nchoices);
pn[0].setChoiceLabels(labels); pn[0].setChoiceLabels(labels);
_onelabClient->set(pn[0]); _onelabClient->set(pn[0]);
} }
} }
} }
delete _onelabClient; delete _onelabClient;
_onelabClient = 0; _onelabClient = 0;
} }
} }
void Message::Barrier() void Message::Barrier()
{ {
#if defined(HAVE_PETSC) #if defined(HAVE_PETSC)
if(_isCommWorld) { if(_isCommWorld) { MPI_Barrier(PETSC_COMM_WORLD); }
MPI_Barrier(PETSC_COMM_WORLD);
}
#endif #endif
} }
#if defined(_OPENMP) #if defined(_OPENMP)
#include <omp.h> #include <omp.h>
int Message::GetNumThreads(){ return omp_get_num_threads(); } int Message::GetNumThreads() { return omp_get_num_threads(); }
void Message::SetNumThreads(int num){ omp_set_num_threads(num); } void Message::SetNumThreads(int num) { omp_set_num_threads(num); }
int Message::GetMaxThreads(){ return omp_get_max_threads(); } int Message::GetMaxThreads() { return omp_get_max_threads(); }
int Message::GetThreadNum(){ return omp_get_thread_num(); } int Message::GetThreadNum() { return omp_get_thread_num(); }
#else #else
int Message::GetNumThreads(){ return 1; } int Message::GetNumThreads() { return 1; }
void Message::SetNumThreads(int num){ } void Message::SetNumThreads(int num) {}
int Message::GetMaxThreads(){ return 1; } int Message::GetMaxThreads() { return 1; }
int Message::GetThreadNum(){ return 0; } int Message::GetThreadNum() { return 0; }
#endif #endif
 End of changes. 152 change blocks. 
315 lines changed or deleted 308 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)