41 #ifndef __USE_STD_IOSTREAM 42 # define __USE_STD_IOSTREAM 53 #if defined(_MSC_VER) && _MSC_VER >= 1400 // Secure versions for VC++ 54 # define GMM_SECURE_CRT 55 # define SECURE_NONCHAR_SSCANF sscanf_s 56 # define SECURE_NONCHAR_FSCANF fscanf_s 57 # define SECURE_STRNCPY(a, la, b, lb) strncpy_s(a, la, b, lb) 58 # define SECURE_FOPEN(F, filename, mode) (*(F) = 0, fopen_s(F, filename, mode)) 59 # define SECURE_SPRINTF1(S, l, st, p1) sprintf_s(S, l, st, p1) 60 # define SECURE_SPRINTF2(S, l, st, p1, p2) sprintf_s(S, l, st, p1, p2) 61 # define SECURE_SPRINTF4(S, l, st, p1, p2, p3, p4) sprintf_s(S, l, st, p1, p2, p3, p4) 62 # define SECURE_STRDUP(s) _strdup(s) 63 # ifndef _SCL_SECURE_NO_DEPRECATE 64 # error Add the option /D_SCL_SECURE_NO_DEPRECATE to the compilation command 67 # define SECURE_NONCHAR_SSCANF sscanf 68 # define SECURE_NONCHAR_FSCANF fscanf 69 # define SECURE_STRNCPY(a, la, b, lb) strncpy(a, b, lb) 70 # define SECURE_FOPEN(F, filename, mode) ((*(F)) = fopen(filename, mode)) 71 # define SECURE_SPRINTF1(S, l, st, p1) sprintf(S, st, p1) 72 # define SECURE_SPRINTF2(S, l, st, p1, p2) sprintf(S, st, p1, p2) 73 # define SECURE_SPRINTF4(S, l, st, p1, p2, p3, p4) sprintf(S, st, p1, p2, p3, p4) 74 # define SECURE_STRDUP(s) strdup(s) 77 inline void GMM_NOPERATION_(
int) { }
78 #define GMM_NOPERATION(a) { GMM_NOPERATION_(abs(&(a) != &(a))); } 92 # error : PLEASE UPDATE g++ TO AT LEAST 4.8 VERSION 127 #include <gmm/gmm_arch_config.h> 130 #if defined(__GNUC__) && (__cplusplus <= 201103L) 131 template<
typename _Tp>
133 {
typedef unique_ptr<_Tp> __single_object; };
134 template<
typename _Tp>
135 struct _MakeUniq<_Tp[]>
136 {
typedef unique_ptr<_Tp[]> __array; };
137 template<
typename _Tp,
size_t _Bound>
138 struct _MakeUniq<_Tp[_Bound]>
139 {
struct __invalid_type { }; };
141 template<
typename _Tp,
typename... _Args>
142 inline typename _MakeUniq<_Tp>::__single_object
143 make_unique(_Args&&... __args)
144 {
return unique_ptr<_Tp>(
new _Tp(std::forward<_Args>(__args)...)); }
146 template<
typename _Tp>
147 inline typename _MakeUniq<_Tp>::__array
148 make_unique(
size_t __num)
149 {
return unique_ptr<_Tp>(
new typename remove_extent<_Tp>::type[__num]()); }
151 template<
typename _Tp,
typename... _Args>
152 inline typename _MakeUniq<_Tp>::__invalid_type
153 make_unique(_Args&&...) =
delete;
159 template <
typename T>
class shared_array_ptr : shared_ptr<T> {
161 shared_array_ptr() {}
162 shared_array_ptr(T *q) :
std::shared_ptr<T>(q, default_delete<T[]>()) {}
163 template <
typename Y> shared_array_ptr(
const std::shared_ptr<Y> &p, T *q)
164 :
std::shared_ptr<T>(p, q) {}
165 T *
get()
const {
return shared_ptr<T>::get(); }
166 T& operator*()
const {
return shared_ptr<T>::operator*(); }
167 T* operator->()
const {
return shared_ptr<T>::operator->(); }
170 template <
typename T> shared_array_ptr<T> make_shared_array(
size_t num)
171 {
return shared_array_ptr<T>(
new T[num]); }
177 #ifdef GMM_HAVE_OPENMP 181 inline size_t num_threads(){
return omp_get_max_threads();}
183 inline size_t this_thread() {
return omp_get_thread_num();}
185 inline bool me_is_multithreaded_now(){
return static_cast<bool>(omp_in_parallel());}
187 inline size_t num_threads(){
return size_t(1);}
188 inline size_t this_thread() {
return size_t(0);}
189 inline bool me_is_multithreaded_now(){
return false;}
194 using std::endl;
using std::cout;
using std::cerr;
195 using std::ends;
using std::cin;
using std::isnan;
199 class standard_locale {
203 inline standard_locale(
void) : cinloc(cin.getloc())
205 if (!me_is_multithreaded_now()){
206 cloc=setlocale(LC_NUMERIC, 0);
207 setlocale(LC_NUMERIC,
"C");
211 inline ~standard_locale() {
212 if (!me_is_multithreaded_now())
213 setlocale(LC_NUMERIC, cloc.c_str());
244 : cloc(setlocale(LC_NUMERIC, 0)), cinloc(cin.getloc())
245 { setlocale(LC_NUMERIC,
"C"); cin.imbue(std::locale(
"C")); }
247 { setlocale(LC_NUMERIC, cloc.c_str()); cin.imbue(cinloc); }
253 class stream_standard_locale {
258 inline stream_standard_locale(std::ios &i)
259 : cloc(i.getloc()), io(i) { io.imbue(std::locale(
"C")); }
260 inline ~stream_standard_locale() { io.imbue(cloc); }
270 # if defined(HAVE_SYS_TIMES) 271 inline double uclock_sec(
void) {
272 static double ttclk = 0.;
273 if (ttclk == 0.) ttclk = sysconf(_SC_CLK_TCK);
274 tms t; times(&t);
return double(t.tms_utime) / ttclk;
277 inline double uclock_sec(
void)
278 {
return double(clock())/double(CLOCKS_PER_SEC); }
287 template <
size_t s>
struct fixed_size_integer_generator {
288 typedef void int_base_type;
289 typedef void uint_base_type;
292 template <>
struct fixed_size_integer_generator<sizeof(char)> {
293 typedef signed char int_base_type;
294 typedef unsigned char uint_base_type;
297 template <>
struct fixed_size_integer_generator<sizeof(short int)
298 - ((sizeof(short int) ==
sizeof(char)) ? 78 : 0)> {
299 typedef signed short int int_base_type;
300 typedef unsigned short int uint_base_type;
303 template <>
struct fixed_size_integer_generator<sizeof(int)
304 - ((sizeof(int) ==
sizeof(
short int)) ? 59 : 0)> {
305 typedef signed int int_base_type;
306 typedef unsigned int uint_base_type;
309 template <>
struct fixed_size_integer_generator<sizeof(long)
310 - ((sizeof(int) ==
sizeof(long)) ? 93 : 0)> {
311 typedef signed long int_base_type;
312 typedef unsigned long uint_base_type;
315 template <>
struct fixed_size_integer_generator<sizeof(long long)
316 - ((sizeof(long long) ==
sizeof(long)) ? 99 : 0)> {
317 typedef signed long long int_base_type;
318 typedef unsigned long long uint_base_type;
321 typedef fixed_size_integer_generator<1>::int_base_type int8_type;
322 typedef fixed_size_integer_generator<1>::uint_base_type uint8_type;
323 typedef fixed_size_integer_generator<2>::int_base_type int16_type;
324 typedef fixed_size_integer_generator<2>::uint_base_type uint16_type;
325 typedef fixed_size_integer_generator<4>::int_base_type int32_type;
326 typedef fixed_size_integer_generator<4>::uint_base_type uint32_type;
327 typedef fixed_size_integer_generator<8>::int_base_type int64_type;
328 typedef fixed_size_integer_generator<8>::uint_base_type uint64_type;
366 #if defined(__GNUC__) && !defined(__ICC) 371 # define IS_DEPRECATED __attribute__ ((__deprecated__)) 375 # define ALWAYS_INLINE __attribute__((always_inline)) 377 # define IS_DEPRECATED 378 # define ALWAYS_INLINE 387 #if defined(EXPORTED_TO_SHARED_LIB) 388 # if defined(_MSC_VER) || defined(__INTEL_COMPILER) 389 # define APIDECL __declspec(dllexport) 390 # elif defined(__GNUC__) 391 # define __attribute__((visibility("default"))) 395 # if defined(IMPORTED_FROM_SHARED_LIB) 396 # error INTENTIONAL COMPILCATION ERROR, DLL IMPORT AND EXPORT ARE INCOMPITABLE 400 #if defined(IMPORTED_FROM_SHARED_LIB) 401 # if defined(_MSC_VER) || defined(__INTEL_COMPILER) 402 # define APIDECL __declspec(dllimport) 406 # if defined(EXPORTED_TO_SHARED_LIB) 407 # error INTENTIONAL COMPILCATION ERROR, DLL IMPORT AND EXPORT ARE INCOMPITABLE 411 #ifndef EXPORTED_TO_SHARED_LIB 412 # ifndef IMPORTED_FROM_SHARED_LIB 413 # define APIDECL //empty, used during static linking
this is the above solutions for linux, but it still needs to be tested.