fix type, more in utils

This commit is contained in:
Joachim Schoeberl 2023-03-05 20:18:27 +01:00
parent 2121ec33f7
commit 16a0f52921
5 changed files with 106 additions and 3 deletions

View File

@ -466,8 +466,8 @@ namespace ngcore
enum { MPI_SUM = 0, MPI_MIN = 1, MPI_MAX = 2, MPI_LOR = 4711 };
inline void MPI_Type_contiguous ( int, MPI_Datatype, MPI_Dataype*) { ; }
inline void MPI_Type_commit ( MPI_Dataype * ) { ; }
inline void MPI_Type_contiguous ( int, MPI_Datatype, MPI_Datatype*) { ; }
inline void MPI_Type_commit ( MPI_Datatype * ) { ; }
class NgMPI_Comm
{

View File

@ -19,5 +19,6 @@
#include "version.hpp"
#include "xbool.hpp"
#include "ngstream.hpp"
#include "utils.hpp"
#endif // NETGEN_CORE_NGCORE_HPP

View File

@ -881,6 +881,30 @@ public:
auto GetNum() const { return num; }
};
/*
// some idea, not yet supported
using namespace std;
template <typename T>
class ParallelValue
{
T val;
public:
ParallelValue (const T & _val) : val(_val) { ; }
operator T () const { return val; }
};
template <typename FUNC> class ParallelFunction
{
FUNC f;
public:
ParallelFunction (const FUNC & _f) : f(_f) { ; }
operator FUNC () const { return f; }
auto operator() (size_t i) const { return f(i); }
};
*/
/* currently not used, plus causing problems on MSVC 2017
template <typename T, typename std::enable_if<ngstd::has_call_operator<T>::value, int>::type = 0>
inline ParallelFunction<T> operator| (const T & func, Tasks tasks)

View File

@ -101,6 +101,26 @@ namespace ngcore
return ToLower(p.string());
}
template <class T>
void SaveBin (std::ostream & ost, const T & val)
{
const char * cp = reinterpret_cast<const char*> (&val);
for (unsigned j = 0; j < sizeof(T); j++)
ost.put(cp[j]);
}
template <class T>
void LoadBin (std::istream & ist, T & val)
{
char * cp = reinterpret_cast<char*> (&val);
for (unsigned j = 0; j < sizeof(T); j++)
ist.get(cp[j]);
}
template<typename T1, typename T2>
std::ostream& operator << (std::ostream& ost, const std::map<T1,T2>& map)
{
@ -117,6 +137,62 @@ namespace ngcore
b = std::move(temp);
}
/// min of 2 values
template <class T>
NETGEN_INLINE T min2 (T a, T b)
{
return (a < b) ? a : b;
}
/// max of 2 values
template <class T>
NETGEN_INLINE T max2 (T a, T b)
{
return (a > b) ? a : b;
}
/// min of 3 values
template <class T>
NETGEN_INLINE T min3 (T a, T b, T c)
{
return (a < b) ? (a < c) ? a : c
: (b < c) ? b : c;
}
/// max of 3 values
template <class T>
NETGEN_INLINE T max3 (T a, T b, T c)
{
///
return (a > b) ? ((a > c) ? a : c)
: ((b > c) ? b : c);
}
/// sign of value (+1, 0, -1)
template <class T>
NETGEN_INLINE int sgn (T a)
{
return (a > 0) ? 1 : ( ( a < 0) ? -1 : 0 );
}
/// square element
template <class T>
NETGEN_INLINE T sqr (const T a)
{
return a * a;
}
/// element to the third power
template <class T>
NETGEN_INLINE T pow3 (const T a)
{
return a * a * a;
}
NETGEN_INLINE double IfPos (double a, double b, double c) { return a>0 ? b : c; }
NETGEN_INLINE double IfZero (double a, double b, double c) { return a==0. ? b : c; }

View File

@ -387,7 +387,7 @@ inline bool operator< (const INDEX_4 & a, const INDEX_4 & b)
/*
@ -425,6 +425,7 @@ inline T max3 (T a, T b, T c)
///
///
template <class T>
inline int sgn (T a)
@ -445,6 +446,7 @@ inline T pow3 (const T a)
{
return a * a * a;
}
*/