Changeset 2765


Ignore:
Timestamp:
Mar 3, 2013 10:48:35 AM (7 years ago)
Author:
bradbell
Message:
  1. Add extra compiler flag so can compile Sacado speed test with c+11 flag.
  2. Improve isnan by assuming compilers get (nan != nan) is true.

nan.cpp: make sure that (nan != nan) returns true.

Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/CMakeLists.txt

    r2762 r2765  
    101101# -Wshadow is left out.
    102102MACRO(add_cppad_cxx_flags target_name)
    103         SET(no_c11    NO)
    104         IF( ${target_name} STREQUAL speed_sacado )
    105                 SET(no_c11 YES)
    106         ENDIF( ${target_name} STREQUAL speed_sacado )
    107103        #
    108104        SET(no_shadow NO)
     
    119115        ENDIF( ${target_name} STREQUAL speed_fadbad )
    120116        #
    121         IF( no_c11 )
    122                 SET(cxx_flags "${cppad_cxx_flags_skip_c11}")
    123         ELSE( no_c11 )
     117        IF( ${target_name} STREQUAL speed_sacado )
     118                SET(cxx_flags "${cppad_cxx_flags_sacado}")
     119        ELSE( ${target_name} STREQUAL speed_sacado )
    124120                IF( no_shadow )
    125121                        SET(cxx_flags "${cppad_cxx_flags_skip_Wshadow}")
     
    127123                        SET(cxx_flags "${cppad_cxx_flags}")
    128124                ENDIF( no_shadow )
    129         ENDIF( no_c11 )
     125        ENDIF( ${target_name} STREQUAL speed_sacado )
    130126        IF( cxx_flags )
    131127                SET_TARGET_PROPERTIES(
     
    210206ENDFOREACH(dir ${cmake_install_libdirs})
    211207# -----------------------------------------------------------------------------
    212 # cppad_cxx_flags_skip_c11
    213 STRING(REGEX REPLACE
    214         "(.*)-std=c[+][+]11(.*)"         "\\1 \\2"
    215         cppad_cxx_flags_skip_c11 "${cppad_cxx_flags}"
    216 )
    217 MESSAGE(STATUS "cppad_cxx_flags_skip_c11 = ${cppad_cxx_flags_skip_c11}")
     208# cppad_cxx_flags_sacado
     209IF( ${cppad_cxx_flags} MATCHES ".*-std=c[+][+]11.*" )
     210        SET(cppad_cxx_flags_sacado "${cppad_cxx_flags} -D HAS_C99_TR1_CMATH" )
     211ELSE( ${cppad_cxx_flags} MATCHES ".*-std=c[+][+]11.*" )
     212        SET(cppad_cxx_flags_sacado ${cppad_cxx_flags} )
     213ENDIF( ${cppad_cxx_flags} MATCHES ".*-std=c[+][+]11.*" )
     214MESSAGE(STATUS "cppad_cxx_flags_sacado = ${cppad_cxx_flags_sacado}")
    218215# -----------------------------------------------------------------------------
    219216# cppad_cxx_flags_skip_Wshadow
  • trunk/cppad/configure.hpp.in

    r2763 r2765  
    5151Does this compiler support the a c++11 null-pointer constant nullptr
    5252(true = 1, false = 0).
    53 
    54 The Sacado speed tests surpress using the c++11 flag because Sacado
    55 does not support it. The cmake test for nullptr does not supress using c++11,
    56 so we fall back to the c++98 standard for the Sacado case.
    5753*/
    58 # ifdef CPPAD_SPEED_SACADO
    59 # define CPPAD_HAS_NULLPTR 0
    60 # else
    6154# define CPPAD_HAS_NULLPTR @CPPAD_HAS_NULLPTR@
    62 # endif
    6355 
    6456 /*!
  • trunk/cppad/local/base_complex.hpp

    r2506 r2765  
    33# define CPPAD_BASE_COMPLEX_INCLUDED
    44/* --------------------------------------------------------------------------
    5 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell
     5CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-13 Bradley M. Bell
    66
    77CppAD is distributed under multiple licenses. This distribution is under
     
    195195namespace CppAD {
    196196        inline bool isnan(const std::complex<double>& z)
    197         {       CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL;   
    198                 static const double nan = std::numeric_limits<double>::quiet_NaN();
    199                 return (z != z) | (z.real() == nan) | (z.imag() == nan);
     197        {       return (z != z);
    200198        }
    201199}
     
    355353        // isnan -------------------------------------------------------------
    356354        inline bool isnan(const std::complex<float>& z)
    357         {       CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL;   
    358                 static const float nan = std::numeric_limits<float>::quiet_NaN();
    359                 return (z != z) | (z.real() == nan) | (z.imag() == nan);
     355        {       return (z != z);
    360356        }
    361357        // Valid standard math functions --------------------------------
  • trunk/cppad/local/parallel_ad.hpp

    r2506 r2765  
    33# define CPPAD_PARALLEL_AD_INCLUDED
    44/* --------------------------------------------------------------------------
    5 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell
     5CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-13 Bradley M. Bell
    66
    77CppAD is distributed under multiple licenses. This distribution is under
     
    1717        CppAD
    1818        num
    19         isnan
    2019        std
    2120$$
     
    4443This routine does extra setup
    4544(and teardown) for the particular $icode Base$$ type.
    46 
    47 $head isnan$$
    48 This routine has the side effect of calling
    49 $codei%
    50         %b% = isnan(%s%)
    51 %$$
    52 where $icode s$$ has type $icode%Base%$$, $codei%AD<%Base%>%$$, and
    53 $codei%std::complex<double>%$$.
    5445
    5546$head CheckSimpleVector$$
     
    9990        elapsed_seconds();
    10091        ErrorHandler::Current();
    101         isnan( std::complex<double>(0.) );
    10292        NumArg(BeginOp);
    10393        one_element_std_set<size_t>();
     
    118108        AD<Base>::tape_manage(tape_manage_clear);
    119109        discrete<Base>::List();
    120         isnan( Base(0.) );
    121         isnan( AD<Base>(0.) );
    122110        CheckSimpleVector< Base, CppAD::vector<Base> >();
    123111        CheckSimpleVector< AD<Base>, CppAD::vector< AD<Base> > >();
  • trunk/cppad/nan.hpp

    r2506 r2765  
    44
    55/* --------------------------------------------------------------------------
    6 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell
     6CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-13 Bradley M. Bell
    77
    88CppAD is distributed under multiple licenses. This distribution is under
     
    4747        %a% != %a%
    4848%$$
    49 Some systems do not get this correct, so we also use the fact that
    50 zero divided by zero should result in a $code nan$$.
    51 To be specific, if a value is not equal to itself or
    52 if it is equal to zero divided by zero, it is considered to be a $code nan$$.
    5349
    5450$head Include$$
     
    140136elements of type $icode Scalar$$.
    141137
    142 $head Parallel Mode$$
    143 $index parallel, user_atomic$$
    144 $index user_atomic, parallel$$
    145 The function $code isnan$$ uses static variables.
    146 Hence for each type $icode Scalar$$,
    147 the first call to
    148 $codei%
    149         %b% = isnan(%s%)
    150 %$$
    151 must not be $cref/parallel/ta_in_parallel/$$ execution mode;
    152 see $code isnan$$ in $cref/parallel_ad/parallel_ad/isnan/$$.
    153 
    154 $head Memory Allocation$$
    155 This function is called by CppAD even if it is not
    156 explicitly referenced by the users code.
    157 Hence any corresponding memory allocation for a static value
    158 of type $icode Scalar$$ my be preformed.
    159 
    160138$children%
    161139        example/nan.cpp
     
    191169template <class Scalar>
    192170inline bool isnan(const Scalar &s)
    193 {       CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL;   
    194         static Scalar scalar_nan = nan( Scalar(0) );   
    195         return (s != s) | (s == scalar_nan);
     171{       return (s != s);
    196172}
    197173
  • trunk/example/nan.cpp

    r2506 r2765  
    11/* $Id$ */
    22/* --------------------------------------------------------------------------
    3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell
     3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-13 Bradley M. Bell
    44
    55CppAD is distributed under multiple licenses. This distribution is under
     
    6464        ok &= CppAD::hasnan(v);
    6565
     66        // check that nan is not equal to itself
     67        ok &= (double_nan != double_nan);
     68
    6669        return ok;
    6770}
  • trunk/omh/multi_thread.omh

    r2577 r2765  
    11/* $Id$ */
    22/* --------------------------------------------------------------------------
    3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell
     3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-13 Bradley M. Bell
    44
    55CppAD is distributed under multiple licenses. This distribution is under
     
    7373$cref/CheckNumericType/CheckNumericType/Parallel Mode/$$,
    7474$cref/discrete functions/Discrete/Parallel Mode/$$,
    75 $cref/nan/nan/Parallel Mode/$$,
    7675$cref/Rosen34/Rosen34/Parallel Mode/$$,
    7776$cref/Runge45/Runge45/Parallel Mode/$$.
  • trunk/omh/whats_new/whats_new_11.omh

    r2599 r2765  
    11$Id$
    22/* --------------------------------------------------------------------------
    3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell
     3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-13 Bradley M. Bell
    44
    55CppAD is distributed under multiple licenses. This distribution is under
     
    610610$lnext
    611611Add $cref/parallel/ta_in_parallel/$$ documentation for,
    612 $cref/nan/nan/Parallel Mode/$$,
     612$code nan$$,
    613613$cref/Rosen34/Rosen34/Parallel Mode/$$, and
    614614$cref/Runge45/Runge45/Parallel Mode/$$.
  • trunk/omh/whats_new/whats_new_13.omh

    r2762 r2765  
    1414$dollar @$$
    1515$spell
     16        isnan
    1617        cmake
    1718        namespace
     
    3435The purpose of this section is to
    3536assist you in learning about changes between various versions of CppAD.
     37
     38$head 03-02$$
     39The function $cref/isnan/nan/$$ no longer allows for systems
     40that return false for $icode%x% != %x%$$ when $icode x$$ is $code NaN$$.
     41This makes the $code isnan$$ function faster.
     42In addition, it removes the need to store a static value
     43which causes complications for parallel execution (as well as other problems).
     44Thus, it is no longer necessary for the first call to $code isnan$$
     45to be during sequential execution and it has been removed from the
     46multi-threading $cref/initialization/multi_thread/Initialization/$$ list.
    3647
    3748$head 03-01$$
  • trunk/speed/main.cpp

    r2762 r2765  
    4141# define AD_PACKAGE "profile"
    4242# endif
    43 // Sacado is a special case because is does not support c+11;
    44 // Hence the setting of this symbol affects all programs that use CppAD.
    45 # ifdef CPPAD_SPEED_SACADO
     43# ifdef SPEED_SACADO
    4644# define AD_PACKAGE "sacado"
    4745# endif
  • trunk/speed/sacado/CMakeLists.txt

    r2762 r2765  
    2727# and below. This command can be used to add any flags, but it was originally
    2828# intended to add preprocessor definitions.
    29 ADD_DEFINITIONS("-DCPPAD_SPEED_SACADO -DRAD_AUTO_AD_Const")
     29ADD_DEFINITIONS("-DSPEED_SACADO -DRAD_AUTO_AD_Const")
    3030
    3131# Local include directories to search (not in package_prefix/includdir)
  • trunk/speed/sacado/makefile.am

    r2762 r2765  
    2525#
    2626# BEGIN OPTIMIZE
    27 AM_CXXFLAGS   = -O2 -DNDEBUG -DCPPAD_SPEED_SACADO \
     27AM_CXXFLAGS   = -O2 -DNDEBUG -DSPEED_SACADO \
    2828        -DRAD_EQ_ALIAS -DRAD_AUTO_AD_Const $(CXX_FLAGS)
    2929# END OPTIMIZE
    3030#
    3131# BEGIN DEBUG
    32 # AM_CXXFLAGS   = -g $(CXX_FLAGS) $(CXX_FLAGS) -DCPPAD_SPEED_SACADO -DRAD_AUTO_AD_Const
     32# AM_CXXFLAGS   = -g $(CXX_FLAGS) $(CXX_FLAGS) -DSPEED_SACADO -DRAD_AUTO_AD_Const
    3333# END DEBUG
    3434#
  • trunk/speed/sacado/makefile.in

    r2764 r2765  
    252252#
    253253# BEGIN OPTIMIZE
    254 AM_CXXFLAGS = -O2 -DNDEBUG -DCPPAD_SPEED_SACADO \
     254AM_CXXFLAGS = -O2 -DNDEBUG -DSPEED_SACADO \
    255255        -DRAD_EQ_ALIAS -DRAD_AUTO_AD_Const $(CXX_FLAGS)
    256256
     
    258258#
    259259# BEGIN DEBUG
    260 # AM_CXXFLAGS   = -g $(CXX_FLAGS) $(CXX_FLAGS) -DCPPAD_SPEED_SACADO -DRAD_AUTO_AD_Const
     260# AM_CXXFLAGS   = -g $(CXX_FLAGS) $(CXX_FLAGS) -DSPEED_SACADO -DRAD_AUTO_AD_Const
    261261# END DEBUG
    262262#
Note: See TracChangeset for help on using the changeset viewer.