adaptations for win32 with MSVC

* missing __declspec import/export for openEMS.dll/nf2ff.dll creation
* SEE2 needs __m128 and operators (see tools/array_ops.h)
* array creation needs new/delete for compile time unknown sizes
* no gettimeofday and Winsock2 instead of sys/time
* missing math defines

Signed-off-by: Thorsten Liebig <liebig@imst.de>
pull/66/head
Thorsten Liebig 2019-12-30 17:12:51 +01:00
parent 9c78459d54
commit fbfccc4110
17 changed files with 156 additions and 38 deletions

View File

@ -8,6 +8,7 @@ ENDIF()
PROJECT(openEMS CXX C)
cmake_minimum_required(VERSION 2.8)
cmake_policy(SET CMP0074 NEW)
# default
set(LIB_VERSION_MAJOR 0)
@ -21,6 +22,8 @@ IF(EXISTS ${PROJECT_SOURCE_DIR}/localConfig.cmake)
include(${PROJECT_SOURCE_DIR}/localConfig.cmake)
ENDIF()
#ADD_DEFINITIONS( -D__SSE2__ )
set(VERSION "v0.0.35")
# add git revision
@ -106,11 +109,18 @@ INCLUDE_DIRECTORIES( ${CSXCAD_INCLUDE_DIR} )
# TinyXML module from https://github.com/ros/cmake_modules
find_package(TinyXML REQUIRED)
ADD_DEFINITIONS( -DTIXML_USE_STL )
message(STATUS "TinyXML_INCLUDE_DIR: ${TinyXML_INCLUDE_DIR}")
message(STATUS "TinyXML_LIBRARY: ${TinyXML_LIBRARY}")
INCLUDE_DIRECTORIES( ${TinyXML_INCLUDE_DIR} )
# hdf5
find_package(HDF5 1.8 COMPONENTS C HL REQUIRED)
INCLUDE_DIRECTORIES (${HDF5_INCLUDE_DIRS})
link_directories(${HDF5_LIBRARIES})
# hdf5 compat
#ADD_DEFINITIONS( -DH5_USE_16_API )
ADD_DEFINITIONS( -DH5_BUILT_AS_DYNAMIC_LIB )
# boost
find_package(Boost 1.46 COMPONENTS
@ -119,7 +129,11 @@ find_package(Boost 1.46 COMPONENTS
date_time
serialization
chrono
REQUIRED
)
message(STATUS "Boost_INCLUDE_DIR: ${Boost_INCLUDE_DIR}")
message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
INCLUDE_DIRECTORIES (${Boost_INCLUDE_DIR})
# vtk
find_package(VTK COMPONENTS vtkIOXML vtkIOGeometry vtkIOLegacy vtkIOPLY NO_MODULE REQUIRED)
@ -193,11 +207,12 @@ if (${MPI_CXX_FOUND})
endif()
add_library( openEMS SHARED ${SOURCES})
#ADD_EXECUTABLE( openEMS main.cpp ${SOURCES})
set_target_properties(openEMS PROPERTIES VERSION ${LIB_VERSION_STRING} SOVERSION ${LIB_VERSION_MAJOR} )
TARGET_LINK_LIBRARIES( openEMS
${CSXCAD_LIBRARIES}
${fparser_LIBRARIES}
tinyxml
${TinyXML_LIBRARY}
${HDF5_LIBRARIES}
${HDF5_HL_LIBRARIES}
${Boost_LIBRARIES}
@ -205,12 +220,21 @@ TARGET_LINK_LIBRARIES( openEMS
${MPI_LIBRARIES}
)
if (WIN32)
# make sure "BUILD_OPENEMS_LIB" is only set for openEMS (dll) not openEMS_bin (exe)
target_compile_definitions(openEMS PRIVATE -DBUILD_OPENEMS_LIB )
endif (WIN32)
# main program
ADD_EXECUTABLE( openEMS_bin main.cpp )
SET_TARGET_PROPERTIES(openEMS_bin PROPERTIES OUTPUT_NAME openEMS)
TARGET_LINK_LIBRARIES(openEMS_bin openEMS)
if (WIN32)
INSTALL(TARGETS openEMS DESTINATION bin)
else()
INSTALL(TARGETS openEMS DESTINATION lib${LIB_SUFFIX})
endif()
INSTALL(TARGETS openEMS_bin DESTINATION bin)
if (UNIX)

View File

@ -203,6 +203,11 @@ void Processing::ShowSnappedCoords()
<< stop[0] << "," << stop[1] << "," << stop[2] << "]" << endl;
}
void Processing::SetProcessInterval(unsigned int interval)
{
ProcessInterval=std::max((unsigned int)1,interval);
}
void Processing::SetProcessStartStopTime(double start, double stop)
{
double dT = Op->GetTimestep();

View File

@ -18,6 +18,10 @@
#ifndef PROCESSING_H
#define PROCESSING_H
#ifndef __GNUC__ // not GCC
#include <emmintrin.h>
#endif
#include <complex>
typedef std::complex<double> double_complex;
#define _I double_complex(0.0,1.0)
@ -31,6 +35,8 @@ typedef std::complex<double> double_complex;
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include "Common/engine_interface_base.h"
class Operator_Base;
@ -59,7 +65,7 @@ public:
virtual void ShowSnappedCoords();
void SetProcessInterval(unsigned int interval) {ProcessInterval=std::max((unsigned int)1,interval);}
void SetProcessInterval(unsigned int interval);
void SetProcessStartStopTime(double start, double stop);
void AddStep(unsigned int step);

View File

@ -26,11 +26,13 @@
#include <boost/fusion/container/list/list_fwd.hpp>
#include <boost/fusion/include/list_fwd.hpp>
//#ifdef WIN32
//#include <Winsock2.h> // for struct timeval
//#endif
#include "tools/useful.h"
#ifndef __GNUC__
#include <Winsock2.h> // for struct timeval
#else
#include <sys/time.h>
#endif
#ifdef MPI_SUPPORT
#define ENGINE_MULTITHREAD_BASE Engine_MPI

View File

@ -33,9 +33,12 @@ set(HEADERS
add_library( nf2ff SHARED ${SOURCES})
set_target_properties(nf2ff PROPERTIES VERSION ${LIB_VERSION_STRING} SOVERSION ${LIB_VERSION_MAJOR})
if (WIN32)
target_compile_definitions(nf2ff PRIVATE -DBUILD_NF2FF_LIB )
endif (WIN32)
TARGET_LINK_LIBRARIES( nf2ff
tinyxml
${TinyXML_LIBRARY}
${HDF5_LIBRARIES}
${Boost_LIBRARIES}
${MPI_LIBRARIES}
@ -46,7 +49,11 @@ SET_TARGET_PROPERTIES(nf2ff_bin PROPERTIES OUTPUT_NAME nf2ff)
TARGET_LINK_LIBRARIES(nf2ff_bin nf2ff)
INSTALL(TARGETS nf2ff_bin DESTINATION bin)
if (WIN32)
INSTALL(TARGETS nf2ff DESTINATION bin)
else()
INSTALL(TARGETS nf2ff DESTINATION lib${LIB_SUFFIX})
endif()
INSTALL(FILES ${HEADERS} DESTINATION include/openEMS)

View File

@ -27,9 +27,20 @@
using namespace std;
#if defined(WIN32)
#ifdef BUILD_NF2FF_LIB
#define NF2FF_EXPORT __declspec(dllexport)
#else
#define NF2FF_EXPORT __declspec(dllimport)
#endif
#else
#define NF2FF_EXPORT
#endif
class TiXmlElement;
class nf2ff
class NF2FF_EXPORT nf2ff
{
public:
nf2ff(vector<float> freq, vector<float> theta, vector<float> phi, vector<float> center, unsigned int numThreads=0);

View File

@ -376,13 +376,13 @@ bool nf2ff_calc::AddSinglePlane(float **lines, unsigned int* numLines, complex<f
normDir[ny]=-1;
unsigned int pos[3];
float edge_length_P[numLines[nP]];
float* edge_length_P = new float[numLines[nP]];
for (unsigned int n=1;n<numLines[nP]-1;++n)
edge_length_P[n]=0.5*fabs(lines[nP][n+1]-lines[nP][n-1]);
edge_length_P[0]=0.5*fabs(lines[nP][1]-lines[nP][0]);
edge_length_P[numLines[nP]-1]=0.5*fabs(lines[nP][numLines[nP]-1]-lines[nP][numLines[nP]-2]);
float edge_length_PP[numLines[nPP]];
float* edge_length_PP = new float[numLines[nPP]];
for (unsigned int n=1;n<numLines[nPP]-1;++n)
edge_length_PP[n]=0.5*fabs(lines[nPP][n+1]-lines[nPP][n-1]);
edge_length_PP[0]=0.5*fabs(lines[nPP][1]-lines[nPP][0]);
@ -422,7 +422,7 @@ bool nf2ff_calc::AddSinglePlane(float **lines, unsigned int* numLines, complex<f
// setup multi-threading jobs
vector<unsigned int> jpt = AssignJobs2Threads(numLines[nP], m_numThreads, true);
m_numThreads = jpt.size();
nf2ff_data thread_data[m_numThreads];
nf2ff_data* thread_data = new nf2ff_data[m_numThreads];
m_Barrier = new boost::barrier(m_numThreads+1); // numThread workers + 1 controller
unsigned int start=0;
unsigned int stop=jpt.at(0)-1;
@ -518,6 +518,9 @@ bool nf2ff_calc::AddSinglePlane(float **lines, unsigned int* numLines, complex<f
Delete2DArray(Np,numAngles);
Delete2DArray(Lt,numAngles);
Delete2DArray(Lp,numAngles);
delete[] edge_length_P; edge_length_P=NULL;
delete[] edge_length_PP; edge_length_PP=NULL;
delete[] thread_data; thread_data=NULL;
m_maxDir = 4*M_PI*P_max / m_radPower;

View File

@ -24,6 +24,7 @@
#include <cmath>
#include <complex>
#include <boost/thread.hpp>
#define _USE_MATH_DEFINES
class nf2ff_calc;

View File

@ -19,10 +19,16 @@
#define OPENEMS_H
#include <sstream>
#ifdef WIN32
#include <Winsock2.h> // for struct timeval
#else
#include <sys/time.h>
#endif
#include <time.h>
#include <vector>
#include "tools/global.h"
#define __OPENEMS_STAT_FILE__ "openEMS_stats.txt"
#define __OPENEMS_RUN_STAT_FILE__ "openEMS_run_stats.txt"
@ -39,7 +45,7 @@ class Engine_Ext_SteadyState;
double CalcDiffTime(timeval t1, timeval t2);
std::string FormatTime(int sec);
class openEMS
class OPENEMS_EXPORT openEMS
{
public:
openEMS();

View File

@ -21,11 +21,9 @@
using namespace std;
#ifdef WIN32
#define __MSVCRT_VERSION__ 0x0700
#include <malloc.h>
//(void**)&array, 16, sizeof(typeof(f4vector**))*numLines[0]
#define MEMALIGN( array, alignment, size ) !(*array = _aligned_malloc( size, alignment ))
#define FREE( array ) _aligned_free( array )
#define MEMALIGN( array, alignment, size ) !(*array = _mm_malloc( size, alignment ))
#define FREE( array ) _mm_free( array )
#else
#define MEMALIGN( array, alignment, size ) posix_memalign( array, alignment, size )
#define FREE( array ) free( array )
@ -70,7 +68,7 @@ void Delete_N_3DArray_v4sf(f4vector**** array, const unsigned int* numLines)
f4vector* Create1DArray_v4sf(const unsigned int numLines)
{
f4vector* array=NULL;
if (MEMALIGN( (void**)&array, 16, sizeof(typeof(f4vector))*numLines ))
if (MEMALIGN( (void**)&array, 16, F4VECTOR_SIZE*numLines ))
{
cerr << "cannot allocate aligned memory" << endl;
exit(3);
@ -92,7 +90,7 @@ f4vector*** Create3DArray_v4sf(const unsigned int* numLines)
f4vector*** array=NULL;
unsigned int pos[3];
if (MEMALIGN( (void**)&array, 16, sizeof(typeof(f4vector**))*numLines[0] ))
if (MEMALIGN( (void**)&array, 16, F4VECTOR_SIZE*numLines[0] ))
{
cerr << "cannot allocate aligned memory" << endl;
exit(3);
@ -100,7 +98,7 @@ f4vector*** Create3DArray_v4sf(const unsigned int* numLines)
//array = new f4vector**[numLines[0]];
for (pos[0]=0; pos[0]<numLines[0]; ++pos[0])
{
if (MEMALIGN( (void**)&array[pos[0]], 16, sizeof(typeof(f4vector*))*numLines[1] ))
if (MEMALIGN( (void**)&array[pos[0]], 16, F4VECTOR_SIZE*numLines[1] ))
{
cerr << "cannot allocate aligned memory" << endl;
exit(3);
@ -108,7 +106,7 @@ f4vector*** Create3DArray_v4sf(const unsigned int* numLines)
//array[pos[0]] = new f4vector*[numLines[1]];
for (pos[1]=0; pos[1]<numLines[1]; ++pos[1])
{
if (MEMALIGN( (void**)&array[pos[0]][pos[1]], 16, sizeof(typeof(f4vector))*numZ ))
if (MEMALIGN( (void**)&array[pos[0]][pos[1]], 16, F4VECTOR_SIZE*numZ ))
{
cerr << "cannot allocate aligned memory" << endl;
exit(3);
@ -129,7 +127,7 @@ f4vector*** Create3DArray_v4sf(const unsigned int* numLines)
f4vector**** Create_N_3DArray_v4sf(const unsigned int* numLines)
{
f4vector**** array=NULL;
if (MEMALIGN( (void**)&array, 16, sizeof(typeof(f4vector***))*3 ))
if (MEMALIGN( (void**)&array, 16, F4VECTOR_SIZE*3 ))
{
cerr << "cannot allocate aligned memory" << endl;
exit(3);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
* Copyright (C) 2010,2019 Thorsten Liebig (Thorsten.Liebig@gmx.de)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -31,14 +31,32 @@
#include <math.h>
#include "constants.h"
typedef float v4sf __attribute__ ((vector_size (16))); // vector of four single floats
typedef int v4si __attribute__ ((vector_size (4*sizeof(int)))); // vector of four single ints
#define F4VECTOR_SIZE 16 // sizeof(typeid(f4vector))
#ifdef __GNUC__ // GCC
typedef float v4sf __attribute__ ((vector_size (F4VECTOR_SIZE))); // vector of four single floats
union f4vector
{
v4sf v;
float f[4];
};
#else // MSVC
#include <emmintrin.h>
union f4vector
{
__m128 v;
float f[4];
};
inline __m128 operator + (__m128 a, __m128 b) {return _mm_add_ps(a, b);}
inline __m128 operator - (__m128 a, __m128 b) {return _mm_sub_ps(a, b);}
inline __m128 operator * (__m128 a, __m128 b) {return _mm_mul_ps(a, b);}
inline __m128 operator / (__m128 a, __m128 b) {return _mm_div_ps(a, b);}
inline __m128 & operator += (__m128 & a, __m128 b){a = a + b; return a;}
inline __m128 & operator -= (__m128 & a, __m128 b){a = a - b; return a;}
inline __m128 & operator *= (__m128 & a, __m128 b){a = a * b; return a;}
inline __m128 & operator /= (__m128 & a, __m128 b){a = a / b; return a;}
#endif
void Delete1DArray_v4sf(f4vector* array);
void Delete3DArray_v4sf(f4vector*** array, const unsigned int* numLines);

View File

@ -19,10 +19,23 @@
#define GLOBAL_H
#include <sstream>
#define _USE_MATH_DEFINES
#include "tools/array_ops.h"
#if defined(WIN32)
#ifdef BUILD_OPENEMS_LIB
#define OPENEMS_EXPORT __declspec(dllexport)
#else
#define OPENEMS_EXPORT __declspec(dllimport)
#endif
#else
#define OPENEMS_EXPORT
#endif
// declare a parameter as unused
#define UNUSED(x) (void)(x);
class Global
class OPENEMS_EXPORT Global
{
public:
Global();
@ -57,9 +70,6 @@ protected:
int m_SavedVerboseLevel;
};
extern Global g_settings;
// declare a parameter as unused
#define UNUSED(x) (void)(x);
OPENEMS_EXPORT extern Global g_settings;
#endif // GLOBAL_H

View File

@ -22,6 +22,7 @@
#include <vector>
#include <complex>
#include <hdf5.h>
#define _USE_MATH_DEFINES
class HDF5_File_Reader
{

View File

@ -404,7 +404,7 @@ bool HDF5_File_Writer::WriteData(std::string dataSetName, hid_t mem_type, void
return false;
}
hsize_t dims[dim];
hsize_t* dims = new hsize_t[dim];
for (size_t n=0;n<dim;++n)
dims[n]=datasize[n];
hid_t space = H5Screate_simple(dim, dims, NULL);
@ -422,6 +422,7 @@ bool HDF5_File_Writer::WriteData(std::string dataSetName, hid_t mem_type, void
H5Sclose(space);
H5Gclose(group);
H5Fclose(hdf5_file);
delete[] dims; dims=NULL;
return true;
}
@ -490,18 +491,22 @@ bool HDF5_File_Writer::WriteAtrribute(std::string locName, std::string attr_name
bool HDF5_File_Writer::WriteAtrribute(std::string locName, std::string attr_name, vector<float> values)
{
float val[values.size()];
float* val = new float[values.size()];
for (size_t n=0;n<values.size();++n)
val[n]=values.at(n);
return HDF5_File_Writer::WriteAtrribute(locName, attr_name,val,values.size(),H5T_NATIVE_FLOAT);
bool ok = HDF5_File_Writer::WriteAtrribute(locName, attr_name,val,values.size(),H5T_NATIVE_FLOAT);
delete[] val; val=NULL;
return ok;
}
bool HDF5_File_Writer::WriteAtrribute(std::string locName, std::string attr_name, vector<double> values)
{
double val[values.size()];
double* val = new double[values.size()];
for (size_t n=0;n<values.size();++n)
val[n]=values.at(n);
return HDF5_File_Writer::WriteAtrribute(locName, attr_name, val, values.size(), H5T_NATIVE_DOUBLE);
bool ok = HDF5_File_Writer::WriteAtrribute(locName, attr_name, val, values.size(), H5T_NATIVE_DOUBLE);
delete[] val; val=NULL;
return ok;
}
bool HDF5_File_Writer::WriteAtrribute(std::string locName, std::string attr_name, float value)

View File

@ -16,6 +16,7 @@
*/
#include <algorithm>
#include "sar_calculation.h"
#include "cfloat"
#include "array_ops.h"

View File

@ -183,3 +183,19 @@ int LinePlaneIntersection(const double *p0, const double *p1, const double *p2,
return 0;
}
#ifndef __GNUC__
#include <chrono>
#include <Winsock2.h> // for struct timeval
int gettimeofday(struct timeval* tp, struct timezone* tzp) {
namespace sc = std::chrono;
sc::system_clock::duration d = sc::system_clock::now().time_since_epoch();
sc::seconds s = sc::duration_cast<sc::seconds>(d);
tp->tv_sec = s.count();
tp->tv_usec = sc::duration_cast<sc::microseconds>(d - s).count();
return 0;
}
#endif // _WIN32

View File

@ -41,4 +41,8 @@ double* Invert(const double* in, double* out);
int LinePlaneIntersection(const double *p0, const double* p1, const double* p2, const double* l_start, const double* l_stop, double* is_point, double &dist);
#ifndef __GNUC__
int gettimeofday(struct timeval* tp, struct timezone* tzp);
#endif // _WIN32
#endif // USEFUL_H