Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Martin Reinecke
ducc
Commits
71536324
Commit
71536324
authored
Jan 02, 2020
by
Martin Reinecke
Browse files
evolution
parent
d06ef1f6
Changes
12
Show whitespace changes
Inline
Side-by-side
src/error_handling.cc
View file @
71536324
...
@@ -25,9 +25,7 @@ using namespace std;
...
@@ -25,9 +25,7 @@ using namespace std;
namespace
mr
{
namespace
mr
{
namespace
error_handling
{
namespace
detail_error_handling
{
namespace
detail
{
bool
abort_in_progress__
=
false
;
bool
abort_in_progress__
=
false
;
...
@@ -45,4 +43,4 @@ void killjob__()
...
@@ -45,4 +43,4 @@ void killjob__()
exit
(
1
);
exit
(
1
);
}
}
}}
}
}}
src/mr_util/aligned_array.h
0 → 100644
View file @
71536324
/*
* This file is part of the MR utility library.
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this code; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Copyright (C) 2019 Max-Planck-Society
Author: Martin Reinecke */
#ifndef MRUTIL_ALIGNED_ARRAY_H
#define MRUTIL_ALIGNED_ARRAY_H
#include <cstdlib>
#include <memory>
namespace
mr
{
namespace
detail_aligned_array
{
using
namespace
std
;
/*! Simple array class guaranteeing 64-byte alignment of the data pointer.
Mostly useful for storing data accessed by SIMD instructions. */
template
<
typename
T
>
class
aligned_array
{
private:
T
*
p
;
size_t
sz
;
#if (__cplusplus >= 201703L)
static
T
*
ralloc
(
size_t
num
)
{
if
(
num
==
0
)
return
nullptr
;
void
*
res
=
aligned_alloc
(
64
,
num
*
sizeof
(
T
));
if
(
!
res
)
throw
bad_alloc
();
return
reinterpret_cast
<
T
*>
(
res
);
}
static
void
dealloc
(
T
*
ptr
)
{
free
(
ptr
);
}
#else // portable emulation
static
T
*
ralloc
(
size_t
num
)
{
if
(
num
==
0
)
return
nullptr
;
void
*
ptr
=
malloc
(
num
*
sizeof
(
T
)
+
64
);
if
(
!
ptr
)
throw
bad_alloc
();
T
*
res
=
reinterpret_cast
<
T
*>
((
reinterpret_cast
<
size_t
>
(
ptr
)
&
~
(
size_t
(
63
)))
+
64
);
(
reinterpret_cast
<
void
**>
(
res
))[
-
1
]
=
ptr
;
return
res
;
}
static
void
dealloc
(
T
*
ptr
)
{
if
(
ptr
)
free
((
reinterpret_cast
<
void
**>
(
ptr
))[
-
1
]);
}
#endif
public:
aligned_array
()
:
p
(
0
),
sz
(
0
)
{}
aligned_array
(
size_t
n
)
:
p
(
ralloc
(
n
)),
sz
(
n
)
{}
aligned_array
(
aligned_array
&&
other
)
:
p
(
other
.
p
),
sz
(
other
.
sz
)
{
other
.
p
=
nullptr
;
other
.
sz
=
0
;
}
~
aligned_array
()
{
dealloc
(
p
);
}
void
resize
(
size_t
n
)
{
if
(
n
==
sz
)
return
;
dealloc
(
p
);
p
=
ralloc
(
n
);
sz
=
n
;
}
T
&
operator
[](
size_t
idx
)
{
return
p
[
idx
];
}
const
T
&
operator
[](
size_t
idx
)
const
{
return
p
[
idx
];
}
T
*
data
()
{
return
p
;
}
const
T
*
data
()
const
{
return
p
;
}
size_t
size
()
const
{
return
sz
;
}
};
}
using
detail_aligned_array
::
aligned_array
;
}
#endif
src/mr_util/error_handling.h
View file @
71536324
...
@@ -27,23 +27,21 @@
...
@@ -27,23 +27,21 @@
namespace
mr
{
namespace
mr
{
namespace
error_handling
{
namespace
detail_error_handling
{
namespace
detail
{
#if defined (__GNUC__)
#if defined (__GNUC__)
#define MR_ERROR_HANDLING_LOC_ ::mr::error_handling::
detail::
CodeLocation(__FILE__, __LINE__, __PRETTY_FUNCTION__)
#define MR
UTIL
_ERROR_HANDLING_LOC_ ::mr::
detail_
error_handling::CodeLocation(__FILE__, __LINE__, __PRETTY_FUNCTION__)
#else
#else
#define MRERROR_HANDLING_LOC_ ::mr::error_handling::
detail::
CodeLocation(__FILE__, __LINE__)
#define MR
UTIL_
ERROR_HANDLING_LOC_ ::mr::
detail_
error_handling::CodeLocation(__FILE__, __LINE__)
#endif
#endif
#define MR_fail(...) \
#define MR_fail(...) \
do { \
do { \
if (!::mr::error_handling::
detail::
abort_in_progress__) \
if (!::mr::
detail_
error_handling::abort_in_progress__) \
{ \
{ \
::mr::error_handling::
detail::
abort_in_progress__ = true; \
::mr::
detail_
error_handling::abort_in_progress__ = true; \
::mr::error_handling::
detail::
streamDump__(::std::cerr, MR_ERROR_HANDLING_LOC_, "\n", ##__VA_ARGS__, "\n"); \
::mr::
detail_
error_handling::streamDump__(::std::cerr, MR
UTIL
_ERROR_HANDLING_LOC_, "\n", ##__VA_ARGS__, "\n"); \
::mr::error_handling::
detail::
killjob__(); \
::mr::
detail_
error_handling::killjob__(); \
} \
} \
::std::exit(1); \
::std::exit(1); \
} while(0)
} while(0)
...
@@ -92,6 +90,6 @@ inline void streamDump__(::std::ostream &os, const T& value,
...
@@ -92,6 +90,6 @@ inline void streamDump__(::std::ostream &os, const T& value,
}
}
#endif
#endif
}}
}
}}
#endif
#endif
src/mr_util/gl_integrator.h
View file @
71536324
...
@@ -28,12 +28,9 @@
...
@@ -28,12 +28,9 @@
namespace
mr
{
namespace
mr
{
namespace
gl_integrator
{
namespace
detail_gl_integrator
{
namespace
detail
{
using
namespace
std
;
using
namespace
std
;
using
namespace
mr
::
threading
;
class
GL_Integrator
class
GL_Integrator
{
{
...
@@ -125,8 +122,8 @@ class GL_Integrator
...
@@ -125,8 +122,8 @@ class GL_Integrator
}
}
using
detail
::
GL_Integrator
;
using
detail
_gl_integrator
::
GL_Integrator
;
}
}
}
#endif
#endif
src/mr_util/simd.h
View file @
71536324
...
@@ -61,7 +61,7 @@ constexpr size_t vbytes = 16;
...
@@ -61,7 +61,7 @@ constexpr size_t vbytes = 16;
template
<
typename
T
,
size_t
len
=
vbytes
/
sizeof
(
T
)>
class
vtp
template
<
typename
T
,
size_t
len
=
vbytes
/
sizeof
(
T
)>
class
vtp
{
{
protected:
protected:
using
Tv
__attribute__
((
vector_size
(
len
*
sizeof
(
T
))
))
=
T
;
using
Tv
[[
gnu
::
vector_size
(
len
*
sizeof
(
T
))
]]
=
T
;
static_assert
((
len
>
0
)
&&
((
len
&
(
len
-
1
))
==
0
),
"bad vector length"
);
static_assert
((
len
>
0
)
&&
((
len
&
(
len
-
1
))
==
0
),
"bad vector length"
);
Tv
v
;
Tv
v
;
...
@@ -104,7 +104,6 @@ template<typename T, size_t len=vbytes/sizeof(T)> class vtp
...
@@ -104,7 +104,6 @@ template<typename T, size_t len=vbytes/sizeof(T)> class vtp
template
<
typename
I
>
void
Set
(
I
i
,
T
val
)
{
v
[
i
]
=
val
;
}
template
<
typename
I
>
void
Set
(
I
i
,
T
val
)
{
v
[
i
]
=
val
;
}
template
<
typename
I
>
T
operator
[](
I
i
)
const
{
return
v
[
i
];
}
template
<
typename
I
>
T
operator
[](
I
i
)
const
{
return
v
[
i
];
}
};
};
}
}
using
detail_simd
::
vtp
;
using
detail_simd
::
vtp
;
...
...
src/mr_util/string_utils.h
View file @
71536324
...
@@ -27,8 +27,6 @@
...
@@ -27,8 +27,6 @@
namespace
mr
{
namespace
mr
{
namespace
string_utils
{
/*! \defgroup stringutilsgroup String handling helper functions */
/*! \defgroup stringutilsgroup String handling helper functions */
/*! \{ */
/*! \{ */
...
@@ -113,6 +111,6 @@ void parse_words_from_file (const std::string &filename,
...
@@ -113,6 +111,6 @@ void parse_words_from_file (const std::string &filename,
/*! \} */
/*! \} */
}
}
}
#endif
#endif
src/mr_util/system.h
View file @
71536324
...
@@ -27,12 +27,10 @@
...
@@ -27,12 +27,10 @@
namespace
mr
{
namespace
mr
{
namespace
system
{
std
::
size_t
getProcessInfo
(
const
std
::
string
&
quantity
);
std
::
size_t
getProcessInfo
(
const
std
::
string
&
quantity
);
std
::
size_t
getMemInfo
(
const
std
::
string
&
quantity
);
std
::
size_t
getMemInfo
(
const
std
::
string
&
quantity
);
std
::
size_t
usable_memory
();
std
::
size_t
usable_memory
();
}
}
}
#endif
#endif
src/mr_util/threading.h
View file @
71536324
...
@@ -38,9 +38,7 @@
...
@@ -38,9 +38,7 @@
namespace
mr
{
namespace
mr
{
namespace
threading
{
namespace
detail_threading
{
namespace
detail
{
using
namespace
std
;
using
namespace
std
;
...
@@ -346,15 +344,14 @@ template<typename Func> void execGuided(size_t nwork,
...
@@ -346,15 +344,14 @@ template<typename Func> void execGuided(size_t nwork,
}
}
}
// end of namespace detail
}
// end of namespace detail
using
detail
::
Scheduler
;
using
detail
_threading
::
Scheduler
;
using
detail
::
execSingle
;
using
detail
_threading
::
execSingle
;
using
detail
::
execStatic
;
using
detail
_threading
::
execStatic
;
using
detail
::
execDynamic
;
using
detail
_threading
::
execDynamic
;
using
detail
::
execGuided
;
using
detail
_threading
::
execGuided
;
// FIXME: missing execParallel(), my_thread(), num_threads()
// FIXME: missing execParallel(), my_thread(), num_threads()
}
// end of namespace threading
}
// end of namespace mr
}
// end of namespace mr
#endif
#endif
src/mr_util/timers.h
View file @
71536324
...
@@ -6,7 +6,6 @@
...
@@ -6,7 +6,6 @@
#include <map>
#include <map>
#include "mr_util/error_handling.h"
#include "mr_util/error_handling.h"
#include "mr_util/string_utils.h"
namespace
mr
{
namespace
mr
{
...
...
src/mr_util/unity_roots.h
0 → 100644
View file @
71536324
/*
* This file is part of the MR utility library.
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this code; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Copyright (C) 2019 Max-Planck-Society
Author: Martin Reinecke */
#ifndef MRUTIL_UNITY_ROOTS_H
#define MRUTIL_UNITY_ROOTS_H
#include <complex>
#include <cmath>
#include <type_traits>
#include <vector>
#include <mr_util/cmplx.h>
namespace
mr
{
namespace
detail_unity_roots
{
using
namespace
std
;
template
<
typename
T
,
typename
Tc
=
complex
<
T
>
>
class
UnityRoots
{
private:
using
Thigh
=
typename
conditional
<
(
sizeof
(
T
)
>
sizeof
(
double
)),
T
,
double
>::
type
;
size_t
N
,
mask
,
shift
;
vector
<
Cmplx
<
Thigh
>>
v1
,
v2
;
static
Cmplx
<
Thigh
>
calc
(
size_t
x
,
size_t
n
,
Thigh
ang
)
{
x
<<=
3
;
if
(
x
<
4
*
n
)
// first half
{
if
(
x
<
2
*
n
)
// first quadrant
{
if
(
x
<
n
)
return
Cmplx
<
Thigh
>
(
cos
(
Thigh
(
x
)
*
ang
),
sin
(
Thigh
(
x
)
*
ang
));
return
Cmplx
<
Thigh
>
(
sin
(
Thigh
(
2
*
n
-
x
)
*
ang
),
cos
(
Thigh
(
2
*
n
-
x
)
*
ang
));
}
else
// second quadrant
{
x
-=
2
*
n
;
if
(
x
<
n
)
return
Cmplx
<
Thigh
>
(
-
sin
(
Thigh
(
x
)
*
ang
),
cos
(
Thigh
(
x
)
*
ang
));
return
Cmplx
<
Thigh
>
(
-
cos
(
Thigh
(
2
*
n
-
x
)
*
ang
),
sin
(
Thigh
(
2
*
n
-
x
)
*
ang
));
}
}
else
{
x
=
8
*
n
-
x
;
if
(
x
<
2
*
n
)
// third quadrant
{
if
(
x
<
n
)
return
Cmplx
<
Thigh
>
(
cos
(
Thigh
(
x
)
*
ang
),
-
sin
(
Thigh
(
x
)
*
ang
));
return
Cmplx
<
Thigh
>
(
sin
(
Thigh
(
2
*
n
-
x
)
*
ang
),
-
cos
(
Thigh
(
2
*
n
-
x
)
*
ang
));
}
else
// fourth quadrant
{
x
-=
2
*
n
;
if
(
x
<
n
)
return
Cmplx
<
Thigh
>
(
-
sin
(
Thigh
(
x
)
*
ang
),
-
cos
(
Thigh
(
x
)
*
ang
));
return
Cmplx
<
Thigh
>
(
-
cos
(
Thigh
(
2
*
n
-
x
)
*
ang
),
-
sin
(
Thigh
(
2
*
n
-
x
)
*
ang
));
}
}
}
public:
UnityRoots
(
size_t
n
)
:
N
(
n
)
{
constexpr
auto
pi
=
3.141592653589793238462643383279502884197
L
;
Thigh
ang
=
Thigh
(
0.25
L
*
pi
/
n
);
size_t
nval
=
(
n
+
2
)
/
2
;
shift
=
1
;
while
((
size_t
(
1
)
<<
shift
)
*
(
size_t
(
1
)
<<
shift
)
<
nval
)
++
shift
;
mask
=
(
size_t
(
1
)
<<
shift
)
-
1
;
v1
.
resize
(
mask
+
1
);
v1
[
0
].
Set
(
Thigh
(
1
),
Thigh
(
0
));
for
(
size_t
i
=
1
;
i
<
v1
.
size
();
++
i
)
v1
[
i
]
=
calc
(
i
,
n
,
ang
);
v2
.
resize
((
nval
+
mask
)
/
(
mask
+
1
));
v2
[
0
].
Set
(
Thigh
(
1
),
Thigh
(
0
));
for
(
size_t
i
=
1
;
i
<
v2
.
size
();
++
i
)
v2
[
i
]
=
calc
(
i
*
(
mask
+
1
),
n
,
ang
);
}
Tc
operator
[](
size_t
idx
)
const
{
if
(
2
*
idx
<=
N
)
{
auto
x1
=
v1
[
idx
&
mask
],
x2
=
v2
[
idx
>>
shift
];
return
Tc
(
T
(
x1
.
r
*
x2
.
r
-
x1
.
i
*
x2
.
i
),
T
(
x1
.
r
*
x2
.
i
+
x1
.
i
*
x2
.
r
));
}
idx
=
N
-
idx
;
auto
x1
=
v1
[
idx
&
mask
],
x2
=
v2
[
idx
>>
shift
];
return
Tc
(
T
(
x1
.
r
*
x2
.
r
-
x1
.
i
*
x2
.
i
),
-
T
(
x1
.
r
*
x2
.
i
+
x1
.
i
*
x2
.
r
));
}
};
}
using
detail_unity_roots
::
UnityRoots
;
}
#endif
src/string_utils.cc
View file @
71536324
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
* This file contains the implementation of various convenience functions
* This file contains the implementation of various convenience functions
* used by the Planck LevelS package.
* used by the Planck LevelS package.
*
*
* Copyright (C) 2002-201
4
Max-Planck-Society
* Copyright (C) 2002-201
9
Max-Planck-Society
* Author: Martin Reinecke
* Author: Martin Reinecke
*/
*/
...
@@ -44,8 +44,6 @@ using namespace std;
...
@@ -44,8 +44,6 @@ using namespace std;
namespace
mr
{
namespace
mr
{
namespace
string_utils
{
string
trim
(
const
string
&
orig
)
string
trim
(
const
string
&
orig
)
{
{
string
::
size_type
p1
=
orig
.
find_first_not_of
(
"
\t
"
);
string
::
size_type
p1
=
orig
.
find_first_not_of
(
"
\t
"
);
...
@@ -332,4 +330,4 @@ void parse_words_from_file (const string &filename, vector<string> &words)
...
@@ -332,4 +330,4 @@ void parse_words_from_file (const string &filename, vector<string> &words)
}
}
}
}
}
}
}
src/system.cc
View file @
71536324
/*
* This file is part of the MR utility library.
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this code; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Copyright (C) 2019 Max-Planck-Society
Author: Martin Reinecke */
#include <regex>
#include <regex>
#include <string>
#include <string>
#include <fstream>
#include <fstream>
...
@@ -8,12 +29,9 @@
...
@@ -8,12 +29,9 @@
#include "mr_util/string_utils.h"
#include "mr_util/string_utils.h"
using
namespace
std
;
using
namespace
std
;
using
namespace
mr
::
string_utils
;
namespace
mr
{
namespace
mr
{
namespace
system
{
namespace
{
namespace
{
string
fileToString
(
const
string
&
fname
)
string
fileToString
(
const
string
&
fname
)
...
@@ -55,4 +73,4 @@ size_t usable_memory()
...
@@ -55,4 +73,4 @@ size_t usable_memory()
return
MemTotal
-
Committed
;
return
MemTotal
-
Committed
;
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment