diff --git a/CMakeLists.txt b/CMakeLists.txt index 80d834a..bbace04 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) -set_target_properties(openEMS PROPERTIES VERSION ${LIB_VERSION_STRING} SOVERSION ${LIB_VERSION_MAJOR}) +#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,13 +220,22 @@ 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) -INSTALL(TARGETS openEMS DESTINATION lib${LIB_SUFFIX}) -INSTALL(TARGETS openEMS_bin DESTINATION bin ) +if (WIN32) + INSTALL(TARGETS openEMS DESTINATION bin) +else() + INSTALL(TARGETS openEMS DESTINATION lib${LIB_SUFFIX}) +endif() +INSTALL(TARGETS openEMS_bin DESTINATION bin) if (UNIX) INSTALL( FILES openEMS.sh diff --git a/Common/processing.cpp b/Common/processing.cpp index a444d9d..9e291ec 100644 --- a/Common/processing.cpp +++ b/Common/processing.cpp @@ -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(); diff --git a/Common/processing.h b/Common/processing.h index 2042706..ab20f78 100644 --- a/Common/processing.h +++ b/Common/processing.h @@ -18,6 +18,10 @@ #ifndef PROCESSING_H #define PROCESSING_H +#ifndef __GNUC__ // not GCC +#include +#endif + #include typedef std::complex double_complex; #define _I double_complex(0.0,1.0) @@ -31,6 +35,8 @@ typedef std::complex double_complex; #include #include +#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); diff --git a/FDTD/engine_multithread.h b/FDTD/engine_multithread.h index 20e7073..dce3b48 100644 --- a/FDTD/engine_multithread.h +++ b/FDTD/engine_multithread.h @@ -26,11 +26,13 @@ #include #include -//#ifdef WIN32 -//#include // for struct timeval -//#endif - +#include "tools/useful.h" +#ifndef __GNUC__ +#include // for struct timeval +#else #include +#endif + #ifdef MPI_SUPPORT #define ENGINE_MULTITHREAD_BASE Engine_MPI diff --git a/nf2ff/CMakeLists.txt b/nf2ff/CMakeLists.txt index 86811b4..ecc8a27 100644 --- a/nf2ff/CMakeLists.txt +++ b/nf2ff/CMakeLists.txt @@ -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) -INSTALL(TARGETS nf2ff DESTINATION lib${LIB_SUFFIX}) +if (WIN32) + INSTALL(TARGETS nf2ff DESTINATION bin) +else() + INSTALL(TARGETS nf2ff DESTINATION lib${LIB_SUFFIX}) +endif() INSTALL(FILES ${HEADERS} DESTINATION include/openEMS) diff --git a/nf2ff/nf2ff.h b/nf2ff/nf2ff.h index 06823af..634989b 100644 --- a/nf2ff/nf2ff.h +++ b/nf2ff/nf2ff.h @@ -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 freq, vector theta, vector phi, vector center, unsigned int numThreads=0); diff --git a/nf2ff/nf2ff_calc.cpp b/nf2ff/nf2ff_calc.cpp index 9c2aa4f..a5ede5e 100644 --- a/nf2ff/nf2ff_calc.cpp +++ b/nf2ff/nf2ff_calc.cpp @@ -376,13 +376,13 @@ bool nf2ff_calc::AddSinglePlane(float **lines, unsigned int* numLines, complex 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 #include #include +#define _USE_MATH_DEFINES class nf2ff_calc; diff --git a/openems.h b/openems.h index 6600e06..2de8118 100644 --- a/openems.h +++ b/openems.h @@ -19,10 +19,16 @@ #define OPENEMS_H #include +#ifdef WIN32 +#include // for struct timeval +#else #include +#endif #include #include +#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(); diff --git a/tools/array_ops.cpp b/tools/array_ops.cpp index 8710b3c..0c50618 100644 --- a/tools/array_ops.cpp +++ b/tools/array_ops.cpp @@ -21,11 +21,9 @@ using namespace std; #ifdef WIN32 -#define __MSVCRT_VERSION__ 0x0700 #include -//(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] #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 +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); diff --git a/tools/global.h b/tools/global.h index c3bb524..bbbd8ae 100644 --- a/tools/global.h +++ b/tools/global.h @@ -19,10 +19,23 @@ #define GLOBAL_H #include +#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 diff --git a/tools/hdf5_file_reader.h b/tools/hdf5_file_reader.h index f190240..4f51caa 100644 --- a/tools/hdf5_file_reader.h +++ b/tools/hdf5_file_reader.h @@ -22,6 +22,7 @@ #include #include #include +#define _USE_MATH_DEFINES class HDF5_File_Reader { diff --git a/tools/hdf5_file_writer.cpp b/tools/hdf5_file_writer.cpp index e3a2113..56d3214 100644 --- a/tools/hdf5_file_writer.cpp +++ b/tools/hdf5_file_writer.cpp @@ -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 values) { - float val[values.size()]; + float* val = new float[values.size()]; for (size_t n=0;n values) { - double val[values.size()]; + double* val = new double[values.size()]; for (size_t n=0;n #include "sar_calculation.h" #include "cfloat" #include "array_ops.h" diff --git a/tools/useful.cpp b/tools/useful.cpp index 50aacfb..209781c 100644 --- a/tools/useful.cpp +++ b/tools/useful.cpp @@ -183,3 +183,19 @@ int LinePlaneIntersection(const double *p0, const double *p1, const double *p2, return 0; } + +#ifndef __GNUC__ +#include +#include // 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(d); + tp->tv_sec = s.count(); + tp->tv_usec = sc::duration_cast(d - s).count(); + + return 0; +} + +#endif // _WIN32 \ No newline at end of file diff --git a/tools/useful.h b/tools/useful.h index dec13ab..ee4f1b3 100644 --- a/tools/useful.h +++ b/tools/useful.h @@ -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