Browse Source

Compiler support for default template arguments

- Using default template arguments in function templates requires C++11
  compiler support. The configure script checks and adds the necessary
  options to CXXFLAGS.
- Fix default template argument repeated at function definition.
- Fix an error in m4/ax_check_quad_precision.m4 which add Intel compiler
  flags for __float128
- Include 'cstdlib' for size_t
Dhairya Malhotra 10 years ago
parent
commit
5b461dd3b6

+ 2 - 1
configure.ac

@@ -66,6 +66,7 @@ DX_PS_FEATURE(OFF)
 DX_INIT_DOXYGEN($PACKAGE_NAME, Doxyfile, doc/doxygen)
 
 
+AX_CXX_DEF_TEMPLATE_ARG
 CHECK_QUAD_PRECISION
 
 # Check for math libs
@@ -168,7 +169,7 @@ AC_SUBST(FLIBS)
 
 
 # Checks for header files.
-AC_CHECK_HEADERS([stdint.h stdlib.h stddef.h])
+AC_CHECK_HEADERS([stdint.h cstdlib cstddef])
 
 
 # Checks for typedefs, structures, and compiler characteristics.

+ 1 - 0
include/cheb_node.hpp

@@ -6,6 +6,7 @@
  */
 
 #include <vector>
+#include <cstdlib>
 #include <stdint.h>
 
 #include <pvfmm_common.hpp>

+ 1 - 0
include/cheb_utils.txx

@@ -8,6 +8,7 @@
 #include <omp.h>
 #include <cmath>
 #include <cassert>
+#include <cstdlib>
 #include <iostream>
 #include <algorithm>
 

+ 1 - 0
include/device_wrapper.hpp

@@ -5,6 +5,7 @@
  * \brief This file contains definition of DeviceWrapper.
  */
 
+#include <cstdlib>
 #include <stdint.h>
 
 #include <pvfmm_common.hpp>

+ 1 - 0
include/fft_wrapper.hpp

@@ -7,6 +7,7 @@
 
 #include <cmath>
 #include <cassert>
+#include <cstdlib>
 #include <vector>
 #include <fftw3.h>
 #ifdef FFTW3_MKL

+ 1 - 0
include/fmm_cheb.hpp

@@ -8,6 +8,7 @@
 
 #include <mpi.h>
 #include <vector>
+#include <cstdlib>
 
 #include <pvfmm_common.hpp>
 #include <precomp_mat.hpp>

+ 1 - 0
include/fmm_gll.hpp

@@ -1,5 +1,6 @@
 
 #include <mpi.h>
+#include <cstdlib>
 
 #include <pvfmm_common.hpp>
 

+ 1 - 0
include/fmm_node.hpp

@@ -6,6 +6,7 @@
  */
 
 #include <vector>
+#include <cstdlib>
 
 #include <pvfmm_common.hpp>
 #include <tree_node.hpp>

+ 1 - 0
include/fmm_pts.hpp

@@ -9,6 +9,7 @@
 #include <mpi.h>
 #include <string>
 #include <vector>
+#include <cstdlib>
 
 #include <pvfmm_common.hpp>
 #include <interac_list.hpp>

+ 2 - 2
include/fmm_pts.txx

@@ -1493,7 +1493,7 @@ void FMM_Pts<FMMNode>::SetupInterac(SetupData<Real_t>& setup_data, bool device){
 }
 
 template <class FMMNode>
-template <int SYNC=__DEVICE_SYNC__>
+template <int SYNC>
 void FMM_Pts<FMMNode>::EvalList(SetupData<Real_t>& setup_data, bool device){
   if(setup_data.interac_data.Dim(0)==0 || setup_data.interac_data.Dim(1)==0){
     Profile::Tic("Host2Device",&this->comm,false,25);
@@ -3098,7 +3098,7 @@ void FMM_Pts<FMMNode>::SetupInteracPts(SetupData<Real_t>& setup_data, bool shift
 }
 
 template <class FMMNode>
-template <int SYNC=__DEVICE_SYNC__>
+template <int SYNC>
 void FMM_Pts<FMMNode>::EvalListPts(SetupData<Real_t>& setup_data, bool device){
   if(setup_data.interac_data.Dim(0)==0 || setup_data.interac_data.Dim(1)==0){
     Profile::Tic("Host2Device",&this->comm,false,25);

+ 1 - 0
include/fmm_tree.txx

@@ -9,6 +9,7 @@
 #include <sstream>
 #include <iomanip>
 #include <cassert>
+#include <cstdlib>
 
 #include <mpi_node.hpp>
 #include <fmm_node.hpp>

+ 1 - 0
include/interac_list.hpp

@@ -8,6 +8,7 @@
  */
 
 #include <vector>
+#include <cstdlib>
 
 #include <pvfmm_common.hpp>
 #include <precomp_mat.hpp>

+ 1 - 0
include/kernel.hpp

@@ -7,6 +7,7 @@
  */
 
 #include <string>
+#include <cstdlib>
 
 #include <pvfmm_common.hpp>
 #include <mem_mgr.hpp>

+ 1 - 0
include/mat_utils.txx

@@ -8,6 +8,7 @@
 #include <omp.h>
 #include <cmath>
 #include <cassert>
+#include <cstdlib>
 #include <algorithm>
 #include <iostream>
 #include <vector>

+ 1 - 0
include/matrix.hpp

@@ -6,6 +6,7 @@
  */
 
 #include <stdint.h>
+#include <cstdlib>
 
 #include <pvfmm_common.hpp>
 #include <vector.hpp>

+ 2 - 0
include/mem_utils.hpp

@@ -5,6 +5,8 @@
  * \brief This file contains memory management utilities.
  */
 
+#include <cstdlib>
+
 #include <pvfmm_common.hpp>
 
 #ifndef _PVFMM_MEM_UTILS_

+ 1 - 0
include/mpi_node.hpp

@@ -8,6 +8,7 @@
 
 #include <vector>
 #include <cassert>
+#include <cstdlib>
 #include <stdint.h>
 
 #include <pvfmm_common.hpp>

+ 2 - 0
include/parUtils.h

@@ -10,6 +10,8 @@
 
 #include <mpi.h>
 #include <vector>
+#include <cstdlib>
+
 #include <vector.hpp>
 
 #ifndef __PVFMM_PAR_UTILS_H_

+ 2 - 2
include/parUtils.txx

@@ -659,7 +659,7 @@ namespace par{
         recv_size=scatter_index.Dim();
 
         long long glb_size[2]={0,0};
-        long long loc_size[2]={data_.Dim()*sizeof(T), recv_size};
+        long long loc_size[2]={(long long)(data_.Dim()*sizeof(T)), recv_size};
         MPI_Allreduce(&loc_size, &glb_size, 2, par::Mpi_datatype<long long>::value(), par::Mpi_datatype<long long>::sum(), comm);
         if(glb_size[0]==0 || glb_size[1]==0) return 0; //Nothing to be done.
         data_dim=glb_size[0]/glb_size[1];
@@ -787,7 +787,7 @@ namespace par{
         recv_size=loc_size;
 
         long long glb_size[3]={0,0};
-        long long loc_size[3]={data_.Dim()*sizeof(T), send_size, recv_size};
+        long long loc_size[3]={(long long)(data_.Dim()*sizeof(T)), send_size, recv_size};
         MPI_Allreduce(&loc_size, &glb_size, 3, par::Mpi_datatype<long long>::value(), par::Mpi_datatype<long long>::sum(), comm);
         if(glb_size[0]==0 || glb_size[1]==0) return 0; //Nothing to be done.
         data_dim=glb_size[0]/glb_size[1];

+ 1 - 0
include/precomp_mat.hpp

@@ -8,6 +8,7 @@
 
 #include <mpi.h>
 #include <vector>
+#include <cstdlib>
 
 #include <pvfmm_common.hpp>
 #include <matrix.hpp>

+ 1 - 0
include/pvfmm.hpp

@@ -7,6 +7,7 @@
 
 #include <mpi.h>
 #include <vector>
+#include <cstdlib>
 #include <cmath>
 
 #include <pvfmm_common.hpp>

+ 1 - 0
include/quad_utils.txx

@@ -7,6 +7,7 @@
 
 #include <omp.h>
 #include <cmath>
+#include <cstdlib>
 #include <iostream>
 #include <iomanip>
 #include <vector>

+ 1 - 0
include/vector.hpp

@@ -6,6 +6,7 @@
  */
 
 #include <vector>
+#include <cstdlib>
 #include <stdint.h>
 
 #include <pvfmm_common.hpp>

+ 2 - 0
m4/ax_check_quad_precision.m4

@@ -20,6 +20,8 @@ AC_DEFUN([CHECK_QUAD_PRECISION],
 
     if test "$cv_quad_prec" = no; then
       cv_quad_type=__float128
+      CFLAGS="$XCFLAGS"
+      CXXFLAGS="$XCXXFLAGS"
       AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[$cv_quad_type q;]])],cv_quad_prec=yes, [])
     fi
 

+ 53 - 0
m4/ax_cxx_def_template_arg.m4

@@ -0,0 +1,53 @@
+# SYNOPSIS
+#
+#   AX_CXX_DEF_TEMPLATE_ARG
+#
+# DESCRIPTION
+#
+#  Check if the compiler supports default template arguments for function
+#  templates and add necessary flags to CXXFLAGS.
+#  
+
+m4_define([_AX_CXX_DEF_TEMPLATE_ARG_testbody], [[
+  template <int T=0>
+  int test(){ return T;};
+]])
+
+AC_DEFUN([AX_CXX_DEF_TEMPLATE_ARG], [dnl
+
+  AC_LANG_PUSH([C++])dnl
+  ac_success=no
+  AC_CACHE_CHECK(whether $CXX supports default template arguments by default,
+  ax_cv_cxx_compile_template,
+  [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_DEF_TEMPLATE_ARG_testbody])],
+    [ax_cv_cxx_compile_template=yes],
+    [ax_cv_cxx_compile_template=no])])
+  if test x$ax_cv_cxx_compile_template = xyes; then
+    ac_success=yes
+  fi
+
+  if test x$ac_success = xno; then
+    for switch in -std=gnu++11 -std=gnu++0x -std=c++11 -std=c++0x; do
+      cachevar=AS_TR_SH([ax_cv_cxx_compile_template_$switch])
+      AC_CACHE_CHECK(whether $CXX default template arguments with $switch,
+                     $cachevar,
+        [ac_save_CXXFLAGS="$CXXFLAGS"
+         CXXFLAGS="$CXXFLAGS $switch"
+         AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_DEF_TEMPLATE_ARG_testbody])],
+          [eval $cachevar=yes],
+          [eval $cachevar=no])
+         CXXFLAGS="$ac_save_CXXFLAGS"])
+      if eval test x\$$cachevar = xyes; then
+        CXXFLAGS="$CXXFLAGS $switch"
+        ac_success=yes
+        break
+      fi
+    done
+  fi
+
+  AC_LANG_POP([C++])
+  if test x$ac_success = xno; then
+    AC_MSG_ERROR([*** Compiler does not support default template arguments in function templates.
+Please use a different compiler or specify the necessary CXXFLAGS.])
+  fi
+])

+ 1 - 0
src/mortonid.cpp

@@ -7,6 +7,7 @@
 
 #include <mortonid.hpp>
 #include <iostream>
+#include <cstdlib>
 #include <cmath>
 
 namespace pvfmm{

+ 1 - 0
src/profile.cpp

@@ -11,6 +11,7 @@
 #include <sstream>
 #include <iomanip>
 #include <cassert>
+#include <cstdlib>
 #include <string>
 #include <vector>
 #include <stack>