Changeset 3755


Ignore:
Timestamp:
Nov 28, 2015 6:19:35 PM (5 years ago)
Author:
bradbell
Message:

merge to branch: trunk
from repository: https://github.com/coin-or/CppAD
start hash code: 7dfec41e8207862aebc5f7ca502453f0aeda4640
end hash code: ab3b2aaac5cbf9d53bec548de1033a6660af44ef

commit ab3b2aaac5cbf9d53bec548de1033a6660af44ef
Author: Brad Bell <bradbell@…>
Date: Sat Nov 28 09:34:18 2015 -0800

Fix Visual Studio compiler errors and warnings.

commit 0a2cb588ef33ece57984b9c58b00eb4cd44a745e
Author: Brad Bell <bradbell@…>
Date: Sat Nov 28 01:54:16 2015 -0800

Remove invisible white space.

commit 3be1e909f7c35c96178965af09d85585af187b7d
Author: Brad Bell <bradbell@…>
Date: Sat Nov 28 01:53:50 2015 -0800

cppad_assert.hpp: remove code that is no longer used.

commit 2e6d69c5aa0f51ab7146436b02b1b737a48ac0d7
Author: Brad Bell <bradbell@…>
Date: Fri Nov 27 15:17:13 2015 -0800

COPYING: old common public license (no longer relevant).

commit 4fd021f782fdb266e9a5e49a22748100126763bd
Author: Brad Bell <bradbell@…>
Date: Fri Nov 27 10:59:48 2015 -0800

Proper checking for parallel execution when modifying statics in ErrorHandler?.


configure.hpp.in: Move CPPAD_NULL from define.hpp to here.
define.hpp: Move CPPAD_NULL from here to configure.hpp.
set_get_in_parallel.hpp: Move from thread_alloc.hpp to here.
thread_alloc.hpp: move out of thread_alloc so can call from ErrorHandler?.

commit 249a1d0263dafbfd3b614a5f7d2788bb5cc871ba
Author: Brad Bell <bradbell@…>
Date: Fri Nov 27 05:49:35 2015 -0800

Fix bug, needed colplack when not specified by cmake command.
cmake.omh: add versbose flag to documentation.

Location:
trunk
Files:
1 added
1 deleted
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/doxyfile.sh

    r3688 r3755  
    5050        ./cppad/local \
    5151        ./cppad/ipopt \
     52        ./cppad_lib \
    5253        ./cppad_ipopt/src \
    5354        ./speed/src
  • trunk/cppad/CMakeLists.txt

    r3744 r3755  
    249249ENDFOREACH( cmake_var )
    250250# -----------------------------------------------------------------------------
    251 # cppad_max_num_threads
     251# check that cppad_max_num_threads is >= 4
    252252#
    253253SET(CMAKE_REQUIRED_INCLUDES  "")
     
    273273}
    274274" )
     275# Using CHECK_CXX_SOURCE_RUNS directly (instead of check_source_runs).
    275276CHECK_CXX_SOURCE_RUNS("${source}" cppad_max_num_threads_is_integer_ge_4)
    276277IF( NOT cppad_max_num_threads_is_integer_ge_4 )
     
    282283# cppad_has_mkstemp
    283284#
    284 SET(CMAKE_REQUIRED_INCLUDES  "")
    285 SET(CMAKE_REQUIRED_LIBRARIES "")
    286 SET(CMAKE_REQUIRED_FLAGS     )
    287285SET(source "
    288286# include <stdlib.h>
     
    294292}
    295293" )
    296 CHECK_CXX_SOURCE_RUNS("${source}" cppad_has_mkstemp )
     294check_source_runs("${source}" cppad_has_mkstemp )
     295# -----------------------------------------------------------------------------
     296# cppad_has_tmpname_s
     297#
     298SET(source "
     299# include <stdio.h>
     300int main(void)
     301{       char filename[L_tmpnam_s ];
     302        if( tmpnam_s(filename, L_tmpnam_s ) != 0 )
     303                return 1;
     304        return 0;
     305}
     306" )
     307check_source_runs("${source}" cppad_has_tmpnam_s )
    297308# -----------------------------------------------------------------------------
    298309# Copy a file to another location and modify its contents.
  • trunk/cppad/configure.hpp.in

    r3744 r3755  
    192192# define CPPAD_HAS_MKSTEMP @cppad_has_mkstemp@
    193193
    194 # endif
     194/*!
     195\def CPPAD_HAS_TMPNAM_S
     196It true, tmpnam_s works in C++ on this system.
     197*/
     198# define CPPAD_HAS_TMPNAM_S @cppad_has_tmpnam_s@
     199
     200// ---------------------------------------------------------------------------
     201// defines that only depend on values above
     202// ---------------------------------------------------------------------------
     203/*!
     204\def CPPAD_NULL
     205This preprocessor symbol is used for a null pointer.
     206
     207If it is not yet defined,
     208it is defined when cppad/local/define.hpp is included.
     209*/
     210# ifndef CPPAD_NULL
     211# if CPPAD_USE_CPLUSPLUS_2011
     212# define CPPAD_NULL     nullptr
     213# else
     214# define CPPAD_NULL     0
     215# endif
     216# endif
     217
     218# endif
  • trunk/cppad/error_handler.hpp

    r2506 r3755  
    33# define CPPAD_ERROR_HANDLER_INCLUDED
    44/* --------------------------------------------------------------------------
    5 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell
     5CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
    66
    77CppAD is distributed under multiple licenses. This distribution is under
    8 the terms of the 
     8the terms of the
    99                    Eclipse Public License Version 1.0.
    1010
     
    5353the current CppAD error handler is used to report an error.
    5454This starts out as a default error handler and can be replaced
    55 using the $code ErrorHandler$$ constructor. 
     55using the $code ErrorHandler$$ constructor.
    5656
    5757$head info$$
     
    6464The argument $icode handler$$ has prototype
    6565$codei%
    66         void (*%handler%) 
     66        void (*%handler%)
    6767                (bool, int, const char *, const char *, const char *);
    6868%$$
     
    8787        int %line%
    8888%$$
    89 It reports the source code line number where the error is detected. 
     89It reports the source code line number where the error is detected.
    9090
    9191$head file$$
     
    9595%$$
    9696and is a $code '\0'$$ terminated character vector.
    97 It reports the source code file where the error is detected. 
     97It reports the source code file where the error is detected.
    9898
    9999$head exp$$
     
    103103%$$
    104104and is a $code '\0'$$ terminated character vector.
    105 It is a source code boolean expression that should have been true, 
     105It is a source code boolean expression that should have been true,
    106106but is false,
    107107and thereby causes this call to $icode handler$$.
     
    131131# include <iostream>
    132132
    133 # ifdef _OPENMP
    134 # include <omp.h>
    135 # endif
    136 
    137133# include <cppad/configure.hpp>
    138 # include <cppad/local/cppad_assert.hpp>
     134# include <cppad/local/set_get_in_parallel.hpp>
    139135# include <cassert>
    140136# include <cstdlib>
    141 
    142 // Cannot use the CPPAD_ASSERT_* macros here because they inturn use the
    143 // error handler. So this code generates a raw assert.
    144 # ifdef _OPENMP
    145 # include <omp.h>
    146 # define CPPAD_ASSERT_NOT_PARALLEL \
    147                 assert( ! omp_in_parallel() );
    148 # else
    149 # define CPPAD_ASSERT_NOT_PARALLEL
    150 # endif
    151137
    152138namespace CppAD { // BEGIN CppAD namespace
     
    156142        friend void parallel_ad(void);
    157143public:
    158         typedef void (*Handler) 
     144        typedef void (*Handler)
    159145                (bool, int, const char *, const char *, const char *);
    160146
    161 
    162         // construct an handler
     147        // construct a new handler
    163148        ErrorHandler(Handler handler) : previous( Current() )
    164         {       CPPAD_ASSERT_NOT_PARALLEL;
     149        {       if( set_get_in_parallel(0) )
     150                {       bool known       = true;
     151                        int  line        = __LINE__;
     152                        const char* file = __FILE__;
     153                        const char* exp  = "! set_get_in_parallel(0)";
     154                        const char* msg  =
     155                                "Using ErrorHandler constructor in parallel mode.";
     156                        Call(known, line, file, exp, msg);
     157                }
    165158                Current() = handler;
    166159        }
     
    168161        // destructor for an error handler
    169162        ~ErrorHandler(void)
    170         {       CPPAD_ASSERT_NOT_PARALLEL;
     163        {       if( set_get_in_parallel(0) )
     164                {       bool known       = true;
     165                        int  line        = __LINE__;
     166                        const char* file = __FILE__;
     167                        const char* exp  = "! set_get_in_parallel(0)";
     168                        const char* msg  =
     169                                "Using ErrorHandler destructor in parallel mode.";
     170                        Call(known, line, file, exp, msg);
     171                }
    171172                Current() = previous;
    172173        }
    173        
     174
    174175        // report an error
    175176        static void Call(
    176                 bool        known, 
    177                 int         line , 
    178                 const char *file , 
     177                bool        known,
     178                int         line ,
     179                const char *file ,
    179180                const char *exp  ,
    180181                const char *msg  )
     
    188189        // The default error handler
    189190        static void Default(
    190                 bool        known, 
    191                 int         line , 
    192                 const char *file , 
     191                bool        known,
     192                int         line ,
     193                const char *file ,
    193194                const char *exp  ,
    194195                const char *msg  )
     
    216217        // current error handler
    217218        static Handler &Current(void)
    218         {
    219 # ifndef NDEBUG
    220 # ifdef _OPENMP
    221                 // This assert would be a CppAD error (not user error)
    222                 static bool first_call = true;
     219        {       static bool first_call = true;
     220                static Handler current = Default;
    223221                if( first_call )
    224                 {       assert( ! omp_in_parallel() );
    225                         first_call = false;
     222                {       if( set_get_in_parallel(0) )
     223                        {       bool known       = false;
     224                                int  line        = __LINE__;
     225                                const char* file = __FILE__;
     226                                const char* exp  = "";
     227                                const char* msg  = "";
     228                                Call(known, line, file, exp, msg);
     229                        }
     230                        first_call = false;
    226231                }
     232                return current;
     233        }
     234};
     235
     236} // END CppAD namespace
     237
     238
     239
    227240# endif
    228 # endif
    229                 static Handler current = Default;
    230                 return current;
    231         }
    232 };
    233 
    234 } // END CppAD namespace
    235 
    236 
    237 
    238 # endif
  • trunk/cppad/local/check_for_nan.hpp

    r3753 r3755  
    136136# include <cppad/configure.hpp>
    137137# include <fstream>
     138
     139# if CPPAD_HAS_MKSTEMP
    138140# include <stdlib.h>
    139 # include <unistd.h>
     141# else
     142# if CPPAD_HAS_TMPNAM_S
     143# include <stdio.h>
     144# else
     145# include <stdlib.h>
     146# endif
     147# endif
     148
    140149
    141150namespace CppAD { // BEGIN_CPPAD_NAMESPACE
     
    153162        close(fd);
    154163# else
    155         file_name = tmpnam( CPPAD_NULL );
     164# if CPPAD_HAS_TMPNAM_S
     165                std::vector<char> name(L_tmpnam_s);
     166                if( tmpnam_s( name.data(), L_tmpnam_s ) != 0 )
     167                {       CPPAD_ASSERT_KNOWN(
     168                                false,
     169                                "Cannot create a temporary file name"
     170                        );
     171                }
     172                file_name = name.data();
     173# else
     174                file_name = tmpnam( CPPAD_NULL );
     175# endif
    156176        std::fstream file_out(file_name.c_str(), std::ios::out|std::ios::binary );
    157177        file_out.write(char_ptr, char_size);
  • trunk/cppad/local/cppad_assert.hpp

    r3701 r3755  
    101101# include <cppad/error_handler.hpp>
    102102
    103 # ifdef _OPENMP
    104 # include <omp.h>
    105 # endif
    106 
    107 
    108103/*!
    109104\def CPPAD_ASSERT_KNOWN(exp, msg)
     
    127122                true       ,                    \
    128123                __LINE__   ,                    \
    129                 __FILE__   ,                    \
     124                __FILE__   ,                    \
    130125                #exp       ,                    \
    131126                msg        );                   \
     
    153148                false      ,                    \
    154149                __LINE__   ,                    \
    155                 __FILE__   ,                    \
     150                __FILE__   ,                    \
    156151                #exp       ,                    \
    157152                ""         );                   \
  • trunk/cppad/local/define.hpp

    r3700 r3755  
    1919*/
    2020
     21// ----------------------------------------------------------------------------
    2122/*!
    2223\def CPPAD_OP_CODE_TYPE
     
    3334
    3435
     36// ----------------------------------------------------------------------------
    3537/*!
    3638\def CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION
     
    5860# endif
    5961
    60 /*!
    61 \def CPPAD_NULL
    62 This preprocessor symbol is used for a null pointer.
    63 
    64 If it is not yet defined,
    65 it is defined when cppad/local/define.hpp is included.
    66 */
    67 # ifndef CPPAD_NULL
    68 # if CPPAD_USE_CPLUSPLUS_2011
    69 # define CPPAD_NULL     nullptr
     62// ----------------------------------------------------------------------------
     63/*!
     64\def CPPAD_LIB_EXPORT
     65Special macro for exporting windows DLL symbols; see
     66https://cmake.org/Wiki/BuildingWinDLL
     67*/
     68# ifdef  _MSC_VER
     69# ifdef  cppad_lib_EXPORTS
     70# define CPPAD_LIB_EXPORT __declspec(dllexport)
    7071# else
    71 # define CPPAD_NULL     0
     72# define CPPAD_LIB_EXPORT __declspec(dllimport)
     73# endif  // cppad_lib_EXPORTS
     74# else   // _MSC_VER
     75# define CPPAD_LIB_EXPORT
    7276# endif
    73 # endif
    74 
     77
     78
     79// ============================================================================
    7580/*!
    7681\def CPPAD_FOLD_ASSIGNMENT_OPERATOR(Op)
  • trunk/cppad/local/undef.hpp

    r3744 r3755  
    6161// Preprecessor definitions that do not presist
    6262# undef CPPAD_ASSERT_NARG_NRES
    63 # undef CPPAD_ASSERT_NOT_PARALLEL
    6463# undef CPPAD_ASSERT_ARG_BEFORE_RESULT
    6564# undef CPPAD_AZMUL
     
    7675# undef CPPAD_HAS_GETTIMEOFDAY
    7776# undef CPPAD_HAS_MKSTEMP
     77# undef CPPAD_HAS_TMPNAM_S
    7878# undef CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION
     79# undef CPPAD_LIB_EXPORT
    7980# undef CPPAD_MAX_NUM_CAPACITY
    8081# undef CPPAD_MIN_DOUBLE_CAPACITY
  • trunk/cppad/thread_alloc.hpp

    r3749 r3755  
    2828# include <cppad/local/cppad_assert.hpp>
    2929# include <cppad/local/define.hpp>
     30# include <cppad/local/set_get_in_parallel.hpp>
    3031namespace CppAD { // BEGIN_CPPAD_NAMESPACE
    3132/*!
    3233\file thread_alloc.hpp
    33 File used to define the CppAD multi-threading allocaor class
     34File used to define the CppAD multi-threading allocator class
    3435*/
    3536
     
    363364        }
    364365        /*!
    365         Set and call the routine that determine if we are in parallel
    366         execution mode.
    367 
    368         \return
    369         value retuned by most recent setting for \a parallel_new.
    370         If \a set is true,
    371         or the most recent setting is \c CPPAD_NULL (its initial value),
    372         the return value is false.
    373         Otherwise the function corresponding to the most recent setting
    374         is called and its value returned by \c set_get_in_parallel.
    375 
    376         \param parallel_new [in]
    377         If \a set is false, \a parallel_new it is not used.
    378         Otherwise, the current value of \c parallel_new becomes the
    379         most recent setting for in_parallel.
    380 
    381         \param set
    382         If \a set is true, then \a parallel_new is becomes the most
    383         recent setting for this \c set_get_in_parallel.
    384         */
    385         static bool set_get_in_parallel(
    386                 bool (*parallel_new)(void) ,
    387                 bool set = false           )
    388         {       static bool (*parallel_user)(void) = CPPAD_NULL;
    389 
    390                 if( set )
    391                 {       parallel_user = parallel_new;
    392                         return false;
    393                 }
    394 
    395                 if( parallel_user == CPPAD_NULL )
    396                         return false;
    397 
    398                 return parallel_user();
    399         }
    400         /*!
    401366        Set and call the routine that determine the current thread number.
    402367
     
    561526                {       bool set = true;
    562527                        set_get_num_threads(num_threads);
    563                         set_get_in_parallel(CPPAD_NULL, set);
     528                        // emphasize that this routine is outside thread_alloc class
     529                        CppAD::set_get_in_parallel(CPPAD_NULL, set);
    564530                        set_get_thread_num(CPPAD_NULL, set);
    565531                        return;
     
    600566                {       bool set = true;
    601567                        set_get_num_threads(num_threads);
    602                         set_get_in_parallel(in_parallel, set);
     568                        // emphasize that this routine is outside thread_alloc class
     569                        CppAD::set_get_in_parallel(in_parallel, set);
    603570                        set_get_thread_num(thread_num, set);
    604571                }
     
    684651        /// other threads are currently executing.
    685652        static bool in_parallel(void)
    686         {       return set_get_in_parallel(0); }
     653        {       // emphasize that this routine is outside thread_alloc class
     654                return CppAD::set_get_in_parallel(0);
     655        }
    687656/* -----------------------------------------------------------------------
    688657$begin ta_thread_num$$
  • trunk/cppad_lib/cppad_colpack.cpp

    r3754 r3755  
    1010Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
    1111-------------------------------------------------------------------------- */
    12 
    1312# include <vector>
     13# include <cppad/vector.hpp>
    1414# include <cppad/configure.hpp>
    15 # include <cppad/vector.hpp>
     15# include <cppad/local/define.hpp>
     16# include <cppad/local/cppad_assert.hpp>
     17
     18# if CPPAD_HAS_COLPACK == 0
     19namespace CppAD {
     20        CPPAD_LIB_EXPORT void this_routine_should_never_get_called(void)
     21        {       CPPAD_ASSERT_UNKNOWN(false); }
     22}
     23# else // CPPAD_HAS_COLPACK
    1624# include <ColPack/ColPackHeaders.h>
    1725
    1826namespace CppAD {       // BEGIN_CPPAD_NAMESPACE
    19 # if CPPAD_HAS_COLPACK  // Requires Colpack library
    2027
    2128/*!
     
    4653*/
    4754// ----------------------------------------------------------------------
    48 void cppad_colpack_general(
     55CPPAD_LIB_EXPORT void cppad_colpack_general(
    4956        CppAD::vector<size_t>&               color         ,
    5057        size_t                               m             ,
     
    130137in the sparsity pattern for the symmetric matrix.
    131138*/
    132 void cppad_colpack_symmetric(
     139CPPAD_LIB_EXPORT void cppad_colpack_symmetric(
    133140        CppAD::vector<size_t>&               color         ,
    134141        size_t                               m             ,
     
    204211}
    205212
    206 # endif
    207213} // END_CPPAD_NAMESPACE
     214
     215# endif // CPPAD_HAS_COLPACK
  • trunk/makefile.am

    r3744 r3755  
    244244        cppad/local/rev_sparse_jac.hpp \
    245245        cppad/local/rev_two.hpp \
     246        cppad/local/set_get_in_parallel.hpp \
    246247        cppad/local/sign.hpp \
    247248        cppad/local/sign_op.hpp \
  • trunk/omh/install/cmake.omh

    r3740 r3755  
    8787$codei%
    8888cmake %%                                                                     \
     89        -D CMAKE_VERBOSE_MAKEFILE=%cmake_verbose_makefile%                       \
    8990    -G %generator%                                                           \
    9091        \
     
    118119%$$
    119120
     121$head cmake_verbose_makefile$$
     122This value should be either $code 0$$ or $code 1$$.
     123The default value, when it is not present, is zero.
     124If it is $code 1$$, then the output of the $code make$$ commands
     125will include all of the files and flags used to run the compiler
     126and linker. This can be useful for seeing how to compile and link
     127your own applications.
     128
    120129$head generator$$
    121130The CMake program is capable of generating different kinds of files.
Note: See TracChangeset for help on using the changeset viewer.