]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Patches by Bob Goodwin: First set of changes for making things work with MS Visual...
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 17 Jun 2012 16:01:28 +0000 (16:01 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 17 Jun 2012 16:01:28 +0000 (16:01 +0000)
git-svn-id: https://svn.dealii.org/trunk@25631 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/configure.in
deal.II/include/deal.II/base/config.h.in
deal.II/source/base/job_identifier.cc
deal.II/source/base/logstream.cc
deal.II/source/base/parameter_handler.cc
deal.II/source/base/thread_management.cc
deal.II/source/base/timer.cc
deal.II/source/base/utilities.cc

index d513f5271b4ee923eda00ae4fb4714f4e0df3382..03b4407238de8872db50ef2ae40ee254da22ff19 100644 (file)
@@ -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
index f65ec3436b659d9f99005d492e7b653a49461200..d7370e47bec047304cd4815e2babcd2de945fb94 100644 (file)
 #  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
index 899e87ea89b736fe476275bc9887a129b9893af6..c09bdcc01b8a89ecfb778f2ad28ed7d4469979cb 100644 (file)
 # include <unistd.h>
 #endif
 
+#ifdef DEAM_II_MSVC
+#  include <WinSock2.h>
+#endif
+
 DEAL_II_NAMESPACE_OPEN
 
 
index 9ea801edcdbdadbf7d4e8e322736b4d05acfe16c..ba6854c99fdc52aec0ad119a7e1ae9f854d8ff9c 100644 (file)
 
 // include sys/resource.h for rusage(). Mac OS X needs sys/time.h then
 // as well (strange), so include that, too.
-#include <sys/resource.h>
+#ifndef DEAL_II_MSVC
+#  include <sys/resource.h>
+#  include <unistd.h>
+#endif
 #include <sys/types.h>
-#include <unistd.h>
 #include <iostream>
 #include <iomanip>
 #include <fstream>
@@ -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.
index 25931f3308e9a2d2cbed8bddfee267bfb1c95d0f..bfa6be40712e6aa0916f9d22b637beab348b4e1c 100644 (file)
 #include <cctype>
 
 #ifdef HAVE_STD_NUMERIC_LIMITS
-# include <limits>
+#  include <limits>
+#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
index 51b98f9232e820edcea5e3421ea6eaa487f54022..033bb2df5cee5ce91029d7052cf57a4ab460c63e 100644 (file)
@@ -25,7 +25,9 @@
 #else
 #  include </usr/include/errno.h>
 #endif
-#include <sys/errno.h>
+#ifndef DEAL_II_MSVC
+#  include <sys/errno.h>
+#endif
 
 #ifdef HAVE_UNISTD_H
 #  include <unistd.h>
@@ -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<unsigned int>(this_id);
   }
index db1038035f362e14d053008acf33dd40e57f6954..3947d792115f2197336513f10f202cd487452018 100644 (file)
 
 // these includes should probably be properly
 // ./configure'd using the AC_HEADER_TIME macro:
-#include <sys/time.h>
-#include <sys/resource.h>
 
+#ifndef DEAL_II_MSVC
+#  include <sys/time.h>
+#  include <sys/resource.h>
+#else
+#  include <windows.h>
+#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;
index 1804d87e8f24a7e64a32fd7c2a62cefd33bb5019..4cd05eb695172ec11a03750b7a6328ae6b1e8d6c 100644 (file)
 #include <ctime>
 #include <cerrno>
 #include <cmath>
-#include <unistd.h>
+
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
+#ifdef DEAL_II_MSVC
+#  include <winsock2.h>
+#endif
+
+#include <boost/math/special_functions/erf.hpp>
+
 #include <sys/types.h>
 #include <sstream>
 #include <iostream>
@@ -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;

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.