From 90a8618c5d93676ca5160327e6191a2aa26ae145 Mon Sep 17 00:00:00 2001 From: bangerth Date: Sun, 17 Jun 2012 16:01:28 +0000 Subject: [PATCH] Patches by Bob Goodwin: First set of changes for making things work with MS Visual C++. git-svn-id: https://svn.dealii.org/trunk@25631 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/configure.in | 11 ++++ deal.II/include/deal.II/base/config.h.in | 11 ++++ deal.II/source/base/job_identifier.cc | 4 ++ deal.II/source/base/logstream.cc | 10 +++- deal.II/source/base/parameter_handler.cc | 11 +++- deal.II/source/base/thread_management.cc | 8 ++- deal.II/source/base/timer.cc | 71 ++++++++++++++++++++++-- deal.II/source/base/utilities.cc | 15 ++++- 8 files changed, 130 insertions(+), 11 deletions(-) diff --git a/deal.II/configure.in b/deal.II/configure.in index d513f5271b..03b4407238 100644 --- a/deal.II/configure.in +++ b/deal.II/configure.in @@ -839,6 +839,17 @@ AH_BOTTOM( # define DEAL_VOLATILE #endif + +/** + * A #define that indicates whether we are using the Microsoft + * Windows Visual C/C++ compiler. We currently do not run ./configure + * on MS Windows, so the detection for this compiler happens via + * the appropriate #ifdef, not through a configuration testcase. + */ +#ifdef _MSC_VER +# define DEAL_II_MSVC +#endif + /* * There is an annoying problem in the Trilinos header ml_config.h: It * #define's HAVE_INTTYPES_H but doesn't give the symbol a value. This diff --git a/deal.II/include/deal.II/base/config.h.in b/deal.II/include/deal.II/base/config.h.in index f65ec3436b..d7370e47be 100644 --- a/deal.II/include/deal.II/base/config.h.in +++ b/deal.II/include/deal.II/base/config.h.in @@ -631,6 +631,17 @@ # define DEAL_VOLATILE #endif + +/** + * A #define that indicates whether we are using the Microsoft + * Windows Visual C/C++ compiler. We currently do not run ./configure + * on MS Windows, so the detection for this compiler happens via + * the appropriate #ifdef, not through a configuration testcase. + */ +#ifdef _MSC_VER +# define DEAL_II_MSVC +#endif + /* * There is an annoying problem in the Trilinos header ml_config.h: It * #define's HAVE_INTTYPES_H but doesn't give the symbol a value. This diff --git a/deal.II/source/base/job_identifier.cc b/deal.II/source/base/job_identifier.cc index 899e87ea89..c09bdcc01b 100644 --- a/deal.II/source/base/job_identifier.cc +++ b/deal.II/source/base/job_identifier.cc @@ -19,6 +19,10 @@ # include #endif +#ifdef DEAM_II_MSVC +# include +#endif + DEAL_II_NAMESPACE_OPEN diff --git a/deal.II/source/base/logstream.cc b/deal.II/source/base/logstream.cc index 9ea801edcd..ba6854c99f 100644 --- a/deal.II/source/base/logstream.cc +++ b/deal.II/source/base/logstream.cc @@ -19,9 +19,11 @@ // include sys/resource.h for rusage(). Mac OS X needs sys/time.h then // as well (strange), so include that, too. -#include +#ifndef DEAL_II_MSVC +# include +# include +#endif #include -#include #include #include #include @@ -321,6 +323,7 @@ LogStream::log_thread_id (const bool flag) void LogStream::print_line_head() { +#ifndef DEAL_II_MSVC rusage usage; double utime = 0.; if (print_utime) @@ -334,6 +337,9 @@ LogStream::print_line_head() utime = diff; } } +#else + double utime = 0.; +#endif /* * The following lines were used for debugging a memory leak. diff --git a/deal.II/source/base/parameter_handler.cc b/deal.II/source/base/parameter_handler.cc index 25931f3308..bfa6be4071 100644 --- a/deal.II/source/base/parameter_handler.cc +++ b/deal.II/source/base/parameter_handler.cc @@ -31,7 +31,16 @@ #include #ifdef HAVE_STD_NUMERIC_LIMITS -# include +# include +#endif + +#ifdef DEAL_II_MSVC +// on Windows systems with MS Visual C/C++, there is a +// #define for 'max' that collides with std::max. So, if +// we find that this is indeed the case, #undef it +# if defined(max) +# undef max +# endif #endif DEAL_II_NAMESPACE_OPEN diff --git a/deal.II/source/base/thread_management.cc b/deal.II/source/base/thread_management.cc index 51b98f9232..033bb2df5c 100644 --- a/deal.II/source/base/thread_management.cc +++ b/deal.II/source/base/thread_management.cc @@ -25,7 +25,9 @@ #else # include #endif -#include +#ifndef DEAL_II_MSVC +# include +#endif #ifdef HAVE_UNISTD_H # include @@ -151,7 +153,11 @@ namespace Threads #elif HAVE_GETPID const pid_t this_id = getpid(); #else +# ifdef DEAL_II_MSVC + const unsigned this_id = 0; +# else const pid_t this_id = 0; +# endif #endif return static_cast(this_id); } diff --git a/deal.II/source/base/timer.cc b/deal.II/source/base/timer.cc index db1038035f..3947d79211 100644 --- a/deal.II/source/base/timer.cc +++ b/deal.II/source/base/timer.cc @@ -23,9 +23,13 @@ // these includes should probably be properly // ./configure'd using the AC_HEADER_TIME macro: -#include -#include +#ifndef DEAL_II_MSVC +# include +# include +#else +# include +#endif // on SunOS 4.x, getrusage is stated in the man pages and exists, but // is not declared in resource.h. declare it ourselves @@ -71,6 +75,36 @@ Timer::Timer(MPI_Comm mpi_communicator, } #endif +#ifdef DEAL_II_MSVC + +namespace +{ + namespace windows + { + double wall_clock() + { + LARGE_INTEGER freq, time; + QueryPerformanceFrequency(&freq); + QueryPerformanceCounter(&time); + return (double) time.QuadPart / freq.QuadPart; + } + + + double cpu_clock() + { + FILETIME cpuTime, sysTime, createTime, exitTime; + if (GetProcessTimes(GetCurrentProcess(), &createTime, + &exitTime, &sysTime, &cpuTime)) + { + return (double)(((unsigned long long)cpuTime.dwHighDateTime << 32) + | cpuTime.dwLowDateTime) / 10e6; + } + return 0; + } + } +} + +#endif void Timer::start () @@ -82,6 +116,14 @@ void Timer::start () MPI_Barrier(mpi_communicator); #endif +#ifdef DEAL_II_MSVC + start_wall_time = windows::wall_clock(); + start_time = windows::cpu_clock(); + start_time_children = start_time; +#else + +//TODO: Break this out into a function like the functions in +//namespace windows above struct timeval wall_timer; gettimeofday(&wall_timer, NULL); start_wall_time = wall_timer.tv_sec + 1.e-6 * wall_timer.tv_usec; @@ -93,6 +135,7 @@ void Timer::start () rusage usage_children; getrusage (RUSAGE_CHILDREN, &usage_children); start_time_children = usage_children.ru_utime.tv_sec + 1.e-6 * usage_children.ru_utime.tv_usec; +#endif } @@ -102,6 +145,13 @@ double Timer::stop () if (running) { running = false; + +#ifdef DEAL_II_MSVC + double time = windows::wall_clock() - start_wall_time; + cumulative_time += windows::cpu_clock() - start_time; +#else +//TODO: Break this out into a function like the functions in +//namespace windows above rusage usage; getrusage (RUSAGE_SELF, &usage); const double dtime = usage.ru_utime.tv_sec + 1.e-6 * usage.ru_utime.tv_usec; @@ -117,7 +167,7 @@ double Timer::stop () gettimeofday(&wall_timer, NULL); double time = wall_timer.tv_sec + 1.e-6 * wall_timer.tv_usec - start_wall_time; - +#endif #ifdef DEAL_II_COMPILER_USE_MPI if (sync_wall_time && Utilities::System::job_supports_mpi()) { @@ -139,6 +189,10 @@ double Timer::operator() () const { if (running) { +#ifdef DEAL_II_MSVC + const double running_time = windows::cpu_clock() - start_time + cumulative_time; + return running_time; +#else rusage usage; getrusage (RUSAGE_SELF, &usage); const double dtime = usage.ru_utime.tv_sec + 1.e-6 * usage.ru_utime.tv_usec; @@ -161,6 +215,7 @@ double Timer::operator() () const return Utilities::MPI::sum (running_time, mpi_communicator); else return running_time; +#endif } else { @@ -177,10 +232,16 @@ double Timer::wall_time () const { if (running) { +#ifdef DEAL_II_MSVC + return 0; +#else struct timeval wall_timer; gettimeofday(&wall_timer, NULL); - return wall_timer.tv_sec + 1.e-6 * wall_timer.tv_usec - start_wall_time + - cumulative_wall_time; + return (wall_timer.tv_sec + + 1.e-6 * wall_timer.tv_usec + - start_wall_time + + cumulative_wall_time); +#endif } else return cumulative_wall_time; diff --git a/deal.II/source/base/utilities.cc b/deal.II/source/base/utilities.cc index 1804d87e8f..4cd05eb695 100644 --- a/deal.II/source/base/utilities.cc +++ b/deal.II/source/base/utilities.cc @@ -23,7 +23,16 @@ #include #include #include -#include + +#ifdef HAVE_UNISTD_H +# include +#endif +#ifdef DEAL_II_MSVC +# include +#endif + +#include + #include #include #include @@ -403,9 +412,11 @@ namespace Utilities unsigned int iteration = 0; while (true) { - const double residual = 0.5+erf(x/std::sqrt(2.)/sigma)/2-y; + const double residual = 0.5+boost::math::erf(x/std::sqrt(2.)/sigma)/2-y; + if (std::fabs(residual) < 1e-7) break; + const double F_prime = 1./std::sqrt(2*3.1415926536)/sigma * std::exp(-x*x/sigma/sigma/2); x += -residual / F_prime; -- 2.39.5