instructions for compiling Elmer on windows

Discussion about building and installing Elmer
mark smith
Posts: 215
Joined: 26 Aug 2009, 18:20
Location: Peterborough, England

instructions for compiling Elmer on windows

Post by mark smith »

Hi the instructions for Compiling Elmer on Windows XP seem to have been removed ( http://www.elmerfem.org/elmerwiki/index ... Windows_XP ), are there any upto date ones to do so on windows 7?
I'd like to add MUMPS support and MPI so any help here would be much appreciated.

Where does the latest source code reside?

Cheers
Mark
mzenker
Posts: 1999
Joined: 07 Dec 2009, 11:49
Location: Germany

Re: instructions for compiling Elmer on windows

Post by mzenker »

Hi,

some time ago, I succeeded to compile Elmersolver under Win XP with Juha's asistance, see this thread: viewtopic.php?f=2&t=2466&start=20#p8060. However, I did not add MUMPS and MPI, and I did not succeed to install the new binaries so that they could be used like the binaries which come with the Windoze installer. But a look into the scripts I posted might help you nevertheless.

It would be a good thing to have a working compilation instruction for a complete Elmer Distribution on Windows XP (32-bit) and 7 (64-bit) including the elmerf90 compiler so that the Elmer team is relieved from constantly providing fresh binaries. I don't have neither the time nor the knowledge to do it, but maybe some people can team together to get it done...

Matthias
david_coe
Posts: 7
Joined: 13 Feb 2014, 11:08
Antispam: Yes

Re: instructions for compiling Elmer on windows

Post by david_coe »

Hi folks!

I've spent some time over the last week or two getting Elmer 7 running as a clean 64bit application set running on Windows 8.1. I've been using two alternative development environments and initial results may be of interest:

1. Cross-compilation under linux ubuntu using the default mingw64 toolchain (the third-party MXE toolchain is even easier to use as many of the Elmer prequisites are preconfigured for building static/shared mingw32/64 libraries).

2. Native compilation using Msys2/Mingw64/Qt4 bundles. The Msys 64bit build-tools are still a bit ideosyncratic (-L and -I libraries sometimes don't get picked up properly) but the compilers have been rock-solid for me.

My intention is to eventually to provide build-script and set of instructions to join the pretty comprehensive set already provided by the Elmer packagers. There's vigorous activity on the SVN server at present, so a push-button, unattended rebuild is a must for me! The autoconf and qmake configurations are proving very robust and, so far, the command-line modules (matc umfpack mathlibs elmergrid meshgen2d eio hutiter fem elmerparam) and Qt modules (ElmerGUI ElmerGUIlogger ElmerGUItester ElmerClips) come up with minimal changes and seem to get through their test suites. The TclTk modules (post front) still await my attention alas.

However, I do have some isssues with the tetgen plugin (tetgen itself is fine). The casting of a pointer to unsigned long gives data loss on the Windows API standard (conformed to by WIN32 and MINGW) which has long as 32bit even if the target is 64bit. Linux-64 and Cygwin-64 have long as 64bit wide so there isn't a problem. My innocent inclination is to replace globally unsigned long by uintptr_t in tetgen.cxx and tetgen.h but this is all quite sophisticated memory allocation stuff and really could do with the original developers' take on it.

More to come in due course but any feedback welcome.

David
raback
Site Admin
Posts: 4812
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: instructions for compiling Elmer on windows

Post by raback »

Hi David

Your efforts are greatly appreciated. We have been busy developing Elmer lately and hence the available packages are not really up-to-date.

We are undergoing a disruptive change as the main build system will be switched to cmake, see
viewtopic.php?f=2&t=3435&start=0&hilit=cmake

This means that many APIs are being rewritten and the old build system won't work. There is a github repo for this work, see
https://github.com/ElmerCSC/elmerfem

I hope that we will jump to the new compilation system sometimes in the summer months. This means that some work on the old autotools won't be usable after this. It is of course a few months so the scripts will be usefull still for some time. Just wanted to open the roadmap a little bit. And as said in the message above help in moving the cmake system and related builds is also welcome.

-Peter
david_coe
Posts: 7
Joined: 13 Feb 2014, 11:08
Antispam: Yes

Re: instructions for compiling Elmer on windows

Post by david_coe »

Good morning, Peter!

Thanks for the heads-up on Cmake - I had noticed their configuration files in among the directories and wondered if change was afoot ;) . I'll try and track what going on on the forum (and github) so the "big-bang" isn't too much of a suprise.

Perhaps it would still be helpful if I gathered up my notes and wrote a short Howto Cross-Compile Elmer for Windows. In principle, addition of the ming32/64 facilities to gcc means the process of cross-compilation to 32/64 bit, static/shared targets is identical whether the host is 32/64bit native windows, cygwin or linux. As usual, the mileage varies with the stability of the toolchains and how much work is needed with the prerequisites!

Regards

David
david_coe
Posts: 7
Joined: 13 Feb 2014, 11:08
Antispam: Yes

Re: instructions for compiling Elmer on windows

Post by david_coe »

64 bit Cross-Compilation of Elmer for Windows

The following note describes the generation of a near complete 64bit-clean set of Windows-targeted Elmer binaries using the M Cross Environment <http://mxe.cc/> under Linux Ubuntu. The Qt4 and FFmpeg libraries needed by the Elmer GUI modules are supplied preconfigured in the MXE archives. The Tcl/Tk libraries required by the Elmer Front and Post modules are not, but can be readily built from primary source.

MXE is, in essence, a highly-convenient, cross-compilation wrapper for the mingw32/mingw64 extensions to GCC on Linux. Its built-in, source-preconfigured libraries can of course be replaced by alternative, prebuilt mingw32/ming64 binaries from the Windows world (and, of course, vice-versa).

Preparing the Compilers

The M Cross Enviroment <http://mxe.cc/> has comprehensive documentation and an extensive preconfigured source library. Choose an appropriate directory and download MXE using:

cd /mxe home location/
export MXE_HOME=$(pwd)

git clone -b stable https://github.com/mxe/mxe.git

Install MXE's list of required native components by issuing on Ubuntu (a Debian-derived Linux system) the instruction:

apt-get install autoconf automake bash bison bzip2 \
cmake flex gettext git g++ intltool \
libffi-dev libtool libltdl-dev libssl-dev \
libxml-parser-perl make openssl patch perl \
pkg-config scons sed unzip wget xz-utils

and, on a 64-bit Debian host, also issue:

apt-get install g++-multilib libc6-dev-i386

Select the required cross-compiler and give the first MXE make command:

export CROSS=x86_64-w64-mingw32

cd $(MXE_HOME)
make MXE_TARGETS=$(CROSS) gcc

which downloads, compiles and installs GCC and associated tools and dependencies. Be warned - MXE will build for all possible targets and libraries unless constrained by its command line or by adjusting the MXE_TARGETS variable in settings.mk.

Place the MXE binaries in your path:

export PATH=$(MXE_HOME)/usr/bin:$PATH

and you're ready to start!

Preparing the Libraries

A few MXE libraries are needed for Elmer's non-GUI modules:

make readline ncurses freetype

The GUI modules need the Qt4 graphics library provided by:

make qt

which downloads, cross-compiles and installs a long list of dependencies:

libodbc++ zlib libgpg_error libgcrypt openssl postgresql libiconv gettext gmp
nettle pcre gnutls freetds libpng jpeg xz tiff lcms1 libmng sqlite expat dbus

ElmerGUIClips need the codecs from the FFmpeg library acquired by:

make ffmpeg

which in turn cross-compiles yet another long list of dependencies:

bzip2 lame pthreads-w32 winpthreads pthreads yasm libvpx opencore-amr opus
sdl speex ogg vorbis theora x264 xvidcore xvidcore freeglut ftgl

MXE doesn't have Tcl/Tk preconfigured in its archive. Cross-compiling from source (downloading either version 8.5 or 8.6) is relatively straightforward following the README instructions in their Win directories and using the same autotools configuration stanzas used later for Elmer.

cd /tcltk code location/
export TCLTK_HOME=$(MXE_HOME)/$(CROSS)/tcltk

modules="tk8.6.1 tcl8.6.1"
for m in $modules; do
cd &m/win
./configure --prefix=$(TCLTK_HOME) --host=$(CROSS)
make -j
make install
cd ../..
done

This will have all taken some time. Fortunately, it only needs to be done once!

Preparing the Elmer Codebase

Download the elmer source code from the CSC svn server to a convenient location:

cd /elmer code location/
export ELMER_CODE=$(pwd)/elmerfem

svn checkout svn://svn.code.sf.net/p/elmerfem/code/trunk elmerfem

Apply the attached local patches using:

patch -p0 < elmer7-6695.patch

These fall into two (very small) groups affecting respectively the primary source-code and the autotools configuration scripts.

The former patches are trivial - Elmer knows about the WIN32 platform and MINGW32/64 is meant to be WIN32 compliant. This does, for example, mean that 'long' is 32bit on both 32bit and 64bit targets whereas in the Unix world 'long' is 32bit on a 32bit target and 64bit on a 64bit target. This is possibly an issue in the tetplugin module where 'long' to 'pointer' casts are used for memory management. Mostly, however, the changes in the code have been to do with the existence or location of include files!

The latter patches are more problematic - the configure files generated by the autotools occasionally fail to locate subsidiary libraries and includes and rerunning autoconf in a cross-compiling environment seem to make the problems worse! It is possible spending a little TLC on the M4 scripts is all that is needed. However, I understand a shift to Cmake is underway, so these provided patches are just cheap-and-cheerful hacks to ensure libraries are found and Microsoft VCC compiler options are removed or replaced by their GCC equivalents.

Building the non-GUI Modules

As expected, there are no code changes required for the Elmer command-line modules.

Mostly the cross-compilers are identified and deployed automatically via the standard autotools procedures but that for F77 needs to be specified manually. Choose an Elmer build location:

export F77=$(CROSS)-gfortran
export ELMER_HOME=/elmer build location/

modules="matc umfpack mathlibs elmergrid meshgen2d eio hutiter fem elmerparam"
for m in $modules; do
cd &m
./configure --prefix=$(ELMER_HOME) --host=$(CROSS)
make -j
make install
cd ..
done

Building the Qt4 GUI Modules

The ElmerGUI, ElmerGUItester and ElmerGUIlogger modules now can be built. Set the GUI build location and identify the correct qmake for the required cross-compilation:

export ELMERGUI_HOME=$(ELMER_HOME)/bin
export QMAKE_HOME=$(MXE_HOME)/$(CROSS)/qt/bin

modules="ElmerGUI ElmerGUItester ElmerGUIlogger"
for m in $modules; do
cd $m
if [ %m == "ElmerGUIlogger" ]; then
$(QMAKE_HOME)/qmake -project
fi
$(QMAKE_HOME)/qmake
make
cp -a release/$(m).exe $(ELMERGUI_HOME)
cd ..
done

cd utils/ElmerClips
$(QMAKE_HOME)/qmake
make
cp -a ElmerClips/ElmerClips.exe $(ELMERGUI_HOME)
cd ../..

Building the Tck/Tk GUI Modules

Neither MXE nor MinGW64 ship with the glaux library. Elmer does - so the code in the glaux_mingw directory must be built and installed within MXE as specified by:

cd post/src/glaux_mingw)
export CFLAGS=-O
./configure --prefix=$(MXE_HOME)/$(CROSS) --host=$(CROSS)
make
make install
cd ../../..

Linking the two two final GUI modulules, front and post, with Tcl/Tk 8.6 gives error diagnostics due to the use of (previously) deprecated constructs in Elmer's calling code. The following (inelegant) workarounds were found; these, however,may, not be honoured in future Tcl/Tk releases.

export CPPFLAGS=-DUSE_INTERP_RESULT
export ac_cv_func_realloc_0_nonnull=yes
export ac_cv_func_malloc_0_nonnull=yes

modules="front post"
for m in $modules; do
cd $m
./configure --prefix=$(ELMER_HOME) --host=$(CROSS)
make -j
make install
cd ..
done

The default build for Tcl/Tk produces shared libraries so it will be necessary to copy the relevant tk86.dll, tcl86.dll and zlib1.dll files to $(ELMER_HOME)/bin.

To Conclude

Elmer (and MXE) afficionadoes will recognise that much of the above has been shamelessly lifted from Elmer and MXE documentation. I am deeply grateful to the developers of both not only for the tools themselves but also for well-targeted information copious enough to jump-start a relatively-innocent newcomer.

The attached patch is against the quite recent svn 6695 release. The above build script fragments produce non-GUI 64bit Windows binaries that (placed in a MINGW64 GCC environment on a 64-bit Windows 8.1 machine) produce an identical fem/tests PASS score as the same version running natively on Linux. The GUI binaries exist and seem functional (ie they run and display random exercises from the manuals) but still need proper testing! The qvt and python options in ElmerGUI, the tetgen plugin and (most crucially) the MPI functionality still remain To Be Done.

Again my thanks. Enjoy!

-- David
david_coe
Posts: 7
Joined: 13 Feb 2014, 11:08
Antispam: Yes

Re: instructions for compiling Elmer on windows

Post by david_coe »

The Source Patches


--- elmerfem/ElmerGUI/Application/src/glwidget.h.orig 2014-04-15 14:48:30.927650224 +0100
+++ elmerfem/ElmerGUI/Application/src/glwidget.h 2014-04-15 14:51:01.097556864 +0100
@@ -51,9 +51,10 @@
UNKNOWNLIST
};

-#ifndef WIN32
+#if defined__MINGW32__ || defined __MINGW64__ || !defined __WIN32__
#include <GL/glu.h>
#endif
+
#include <QGLWidget>
#include <QHash>
#include <QVector>
--- elmerfem/post/src/glaux_mingw/src/font.c.orig 2014-04-15 14:46:13.921906444 +0100
+++ elmerfem/post/src/glaux_mingw/src/font.c 2014-04-15 14:51:01.109556982 +0100
@@ -37,7 +37,7 @@
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
-#include <gl/glaux.h>
+#include <GL/glaux.h>
#include "tk.h"

#define static
--- elmerfem/post/src/glaux_mingw/src/image.c.orig 2014-04-15 14:46:13.929906595 +0100
+++ elmerfem/post/src/glaux_mingw/src/image.c 2014-04-15 14:51:01.109556982 +0100
@@ -34,7 +34,7 @@
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
-#include <gl/glaux.h>
+#include <GL/glaux.h>
#include "tk.h"

#define static
--- elmerfem/post/src/glaux_mingw/src/shapes.c.orig 2014-04-15 14:46:13.929906595 +0100
+++ elmerfem/post/src/glaux_mingw/src/shapes.c 2014-04-15 14:51:01.109556982 +0100
@@ -40,7 +40,7 @@
#include <math.h>
#include <GL/gl.h>
#include <GL/glu.h>
-#include <gl/glaux.h>
+#include <GL/glaux.h>
#include "3d.h"

#define static
--- elmerfem/post/src/glaux_mingw/src/teapot.c.orig 2014-04-15 14:46:13.929906595 +0100
+++ elmerfem/post/src/glaux_mingw/src/teapot.c 2014-04-15 14:51:01.109556982 +0100
@@ -39,7 +39,7 @@
*/
#include <windows.h>
#include <GL/gl.h>
-#include <gl/glaux.h>
+#include <GL/glaux.h>
#include "teapot.h"

#define static
--- elmerfem/utils/ElmerClips/src/encoder.cpp.orig 2014-04-15 14:46:44.166429103 +0100
+++ elmerfem/utils/ElmerClips/src/encoder.cpp 2014-04-15 14:51:01.109556982 +0100
@@ -192,7 +192,7 @@

// Init encoder:
//---------------
- CodecID codec_id = CODEC_ID_MPEG1VIDEO;
+ AVCodecID codec_id = CODEC_ID_MPEG1VIDEO;

AVCodec *codec = avcodec_find_encoder(codec_id);
david_coe
Posts: 7
Joined: 13 Feb 2014, 11:08
Antispam: Yes

Re: instructions for compiling Elmer on windows

Post by david_coe »

The Configuration Patches

--- elmerfem/ElmerGUI/Application/Application.pro.orig 2014-04-15 14:48:24.843602616 +0100
+++ elmerfem/ElmerGUI/Application/Application.pro 2014-04-15 14:51:01.097556864 +0100
@@ -32,9 +32,9 @@

# QMAKE_LFLAGS += -Wl,-rpath,$$(VTKHOME)/lib/vtk-5.2

-win32 {
- QMAKE_LFLAGS += /NODEFAULTLIB:library
-}
+# win32 {
+# QMAKE_LFLAGS += /NODEFAULTLIB:library
+# }

QMAKE_CXXFLAGS_DEBUG += -g
QMAKE_CXXFLAGS += -g
--- elmerfem/ElmerGUI/matc/matc.pro.orig 2014-04-15 14:48:37.015695578 +0100
+++ elmerfem/ElmerGUI/matc/matc.pro 2014-04-15 14:51:01.097556864 +0100
@@ -11,7 +11,7 @@
OBJECTS_DIR = obj
win32 {
DEFINES = WIN32 _CRT_SECURE_NO_WARNINGS
- SOURCES = src\*.c
+ SOURCES = src/*.c
} else {
SOURCES = src/*.c
}
--- elmerfem/ElmerGUI/ElmerGUI.pri.orig 2014-04-15 14:48:22.651584891 +0100
+++ elmerfem/ElmerGUI/ElmerGUI.pri 2014-04-15 14:51:01.121557100 +0100
@@ -7,17 +7,17 @@
#------------------------------------------------------------------------------
# Optional components (undefine or comment out to exclude from compilation):
#------------------------------------------------------------------------------
-DEFINES += EG_QWT # Use QWT for convergence monitor?
-DEFINES += EG_VTK # Use VTK for postprocessing?
+#DEFINES += EG_QWT # Use QWT for convergence monitor?
+#DEFINES += EG_VTK # Use VTK for postprocessing?
DEFINES += EG_PARAVIEW # Use ParaView for postprocessing?
-DEFINES += EG_MATC # Use MATC for internal operations in postprocessing?
-DEFINES += EG_OCC # Use OpenCASCADE 6.3 for importing CAD files? Needs VTK.
-DEFINES -= EG_PYTHONQT # Use PythonQt for scripting in post processor?
+#DEFINES += EG_MATC # Use MATC for internal operations in postprocessing?
+#DEFINES += EG_OCC # Use OpenCASCADE 6.3 for importing CAD files? Needs VTK.
+#DEFINES -= EG_PYTHONQT # Use PythonQt for scripting in post processor?

#------------------------------------------------------------------------------
# 64 bit system?
#------------------------------------------------------------------------------
-BITS = 32
+BITS = 64


#------------------------------------------------------------------------------
@@ -28,7 +28,7 @@
ELMER_HOME = $$(ELMER_HOME)
isEmpty(ELMER_HOME) {
unix: ELMER_HOME = /usr/local
- win32: ELMER_HOME = c:/Elmer7
+ win32: ELMER_HOME = /win/elmer
macx: ELMER_HOME = /usr/local
}
ELMERGUI_HOME = $${ELMER_HOME}/bin
--- elmerfem/utils/ElmerClips/ElmerClips.pro.orig 2014-04-15 14:46:44.458433709 +0100
+++ elmerfem/utils/ElmerClips/ElmerClips.pro 2014-04-15 14:51:01.109556982 +0100
@@ -4,9 +4,9 @@
INCLUDEPATH += . src

win32 {
- INCLUDEPATH += D:/ffmpeg/include src/win32
- QMAKE_LIBDIR += D:/ffmpeg/bin
- LIBS += -lavcodec -lavutil -lswscale
+ INCLUDEPATH += /opt/mxe/usr/x86_64-w64-mingw32.static/include
+ QMAKE_LIBDIR += /opt/mxe/usr/x86_64-w64-mingw32.static/lib
+ LIBS += -lavcodec -lavutil -lswscale -liconv -lmp3lame -lopencore-amrnb -lopencore-amrwb -lopus -lspeex -ltheora -lvo-aacenc -lvo-amrwbenc -lvorbis -lvorbisenc -lvpx -lx264 -lxvidcore -logg
DESTDIR = ElmerClips
}

--- elmerfem/front/configure.orig 2014-04-15 14:46:37.886327969 +0100
+++ elmerfem/front/configure 2014-04-15 14:51:01.101556903 +0100
@@ -7350,7 +7350,7 @@
fi

acx_tcltk_lib_versions="8.6 8.5 8.4 8.3 8.2 8.1 86 85 84 83 82 81"
-acx_tcltk_locations="/usr/lib /usr/local/lib /usr/swf/lib"
+acx_tcltk_locations="/win/tcltk/lib /usr/lib /usr/local/lib /usr/swf/lib"

# Generic TCLTK library?
if test "$acx_tcltk_ok" = no; then
@@ -7498,7 +7498,7 @@
if test "$TCLTK_INCPATH"; then
acx_tcltk_tcl_h_locs=$TCLTK_INCPATH
fi
-acx_tcltk_tcl_h_locs="$acx_tcltk_tcl_h_locs /usr/include /usr/local/include /include /usr/swf/include /sw/include /sw/usr/include /really/weird/place /ok/I/quit"
+acx_tcltk_tcl_h_locs="$acx_tcltk_tcl_h_locs /win/tcltk/include /usr/include /usr/local/include /include /usr/swf/include /sw/include /sw/usr/include /really/weird/place /ok/I/quit"
acx_tcltk_CPPFLAGS_save=$CPPFLAGS
acx_tcltk_CFLAGS_save=$CFLAGS

--- elmerfem/post/configure.orig 2014-04-15 14:46:09.057813676 +0100
+++ elmerfem/post/configure 2014-04-15 14:51:01.105556942 +0100
@@ -9841,7 +9841,7 @@
fi

acx_tcltk_lib_versions="8.6 8.5 8.4 8.3 8.2 8.1 86 85 84 83 82 81"
-acx_tcltk_locations="/usr/lib /usr/local/lib /usr/swf/lib"
+acx_tcltk_locations="/win/tcltk/lib /usr/lib /usr/local/lib /usr/swf/lib"

# Generic TCLTK library?
if test "$acx_tcltk_ok" = no; then
@@ -10005,7 +10005,7 @@
if test "$TCLTK_INCPATH"; then
acx_tcltk_tcl_h_locs=$TCLTK_INCPATH
fi
-acx_tcltk_tcl_h_locs="$acx_tcltk_tcl_h_locs /usr/include /usr/local/include /include /usr/swf/include /sw/include /sw/usr/include /really/weird/place /ok/I/quit"
+acx_tcltk_tcl_h_locs="$acx_tcltk_tcl_h_locs /win/tcltk/include /usr/include /usr/local/include /include /usr/swf/include /sw/include /sw/usr/include /really/weird/place /ok/I/quit"
acx_tcltk_CPPFLAGS_save=$CPPFLAGS
acx_tcltk_CFLAGS_save=$CFLAGS

@@ -10539,10 +10539,10 @@
#
acx_ft_ok=no

-acx_ft_locs="$FTCONFIG /usr/local/bin /usr/bin"
+acx_ft_locs="$FTCONFIG /win/mxe/usr/x86_64-w64-mingw32/bin /usr/local/bin /usr/bin"

if test "$acx_platform_def" = "WIN32"; then
- acx_ft_locs="$acx_ft_locs /mingw/bin"
+ acx_ft_locs="$acx_ft_locs /win/mxe/usr/x86_64-w64-mingw32/bin"
fi

for v in $acx_ft_locs; do
plankton
Posts: 2
Joined: 20 Apr 2014, 20:16
Antispam: Yes

Re: instructions for compiling Elmer on windows

Post by plankton »

Hi All,

My first post here, but hopefully a useful one.
I managed to cross-compile Elmer for windows WITH MPI under Ubuntu Linux.
It involves installing the MS MPI package on a windows system and then preparing it for cross-compilation as described in the following script.
Admittedly, the script is not the most elegant one, but it should give you the idea how to do it.
The script below also gives directions what to do before compilation and how to run mpiexec in windows.

First make sure you have the latest source and install it in ~/elmer_source

Code: Select all

cd ~
mkdir elmer_source
cd elmer_source
svn checkout svn://svn.code.sf.net/p/elmerfem/code/trunk ./
After that prepare the MPI installation as described in the script.
Then copy the script text below into "compileElmerMPI.sh" and run it with "sh ./compileElmerMPI.sh >compileout.out"

I tested it with Ubuntu 12.04 and the latest Elmer source.
I assume a similar approach can be undertaken in cygwin or mingw64 under windows (?).

Enjoy,

- Anton

---

The script is:

Code: Select all


# compileElmerMPI.sh
#
#
# make sure you have the correct prerequisites for Elmer (linux)
#
# in linux:
# install the MinGW-w64 cross-compiler and tools (esp. gendef (needed for MPI lib))
# e.g. sudo apt-get install gfortran-mingw-w64 gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 mingw-w64-tools
#
# 
#
# ========================================================================
# the following only needs to be done in case of clean install
# however, for the script, make sure the src is installed in
# $HOME/elmer_source
# ========================================================================

# cd ~
# mkdir elmer_source
# cd elmer_source
# svn checkout svn://svn.code.sf.net/p/elmerfem/code/trunk ./

# ========================================================================
# the following is taken from:
# http://www.symscape.com/configure-msmpi-for-mingw-w64
# How to Configure MSMPI for the MinGW-w64 Cross-Compiler
# by Symscape
# 
# on your windows machine:
# 1. Install MS-MPI Redistributable Package on Windows
# download: http://www.microsoft.com/en-us/download/details.aspx?id=36045
# select mpi_x64.Msi
# install on windows (x64)
# Copy C:\Program Files\Microsoft HPC Pack 2012 to a temp location <msmpi-windows-home>
# (e.g., D:\projects\mpi\ms-hpc) then 
# copy C:\Windows\System32\msmpi.dll to <msmpi-windows-home>\Lib\amd64\.
#
# Transfer <msmpi-windows-home> to Linux.
#
# ========================================================================
# for the purpose of this script; transfer it to ~/elmer_source/msmpi/
# ========================================================================
# 
# ========================================================================
# some other things you need to change before compiling:
# 
# Fix missing __int64 definition
# You will need to add #include <stdint.h> to <msmpi-linux-home>/Inc/mpi.h:127 to define __int64.
#
#
# and for Fortran:
# <msmpi-linux-home>/Inc/mpif.h:341:
# change the defined rule for MPI_AINT to default to win64
# ! !DEC$ IF DEFINED (_WIN64)
#       PARAMETER (MPI_AINT=z'4c00083b')
# ! !DEC$ ELSE
# !      PARAMETER (MPI_AINT=z'4c00043b')
# ! !DEC$ ENDIF
#
# also comment out the MPI_ADDRESS_KIND parameter:
# <msmpi-linux-home>/Inc/mpif.h:359:
# !       PARAMETER (MPI_ADDRESS_KIND=INT_PTR_KIND())
#
# ========================================================================

# set-up the install directory
# this script installs Elmer in $HOME/ElmerMPI

# ========================================================================
# at this point you should have elmer_source with the latest source code
# also make sure that the msmpi directory is present with the changes described above
# ========================================================================

# ========================================================================
# make MPI libs
# ========================================================================

cd ~
mkdir ElmerMPI
cd elmer_source
cd msmpi/Lib/amd64
gendef msmpi.dll
x86_64-w64-mingw32-dlltool -d msmpi.def -l libmsmpi.a -D msmpi.dll

cd ~/elmer_source

# ========================================================================
# main exports
# ========================================================================
export CC=x86_64-w64-mingw32-gcc
export CXX=x86_64-w64-mingw32-g++
export FC=x86_64-w64-mingw32-gfortran
export F77=x86_64-w64-mingw32-gfortran

# ========================================================================
# matc, umfpack
# ========================================================================

cd matc
./configure --prefix=$HOME/ElmerMPI --host=x86_64-w64-mingw32
make
make install
cd ..

cd umfpack
./configure --prefix=$HOME/ElmerMPI --host=x86_64-w64-mingw32
make
make install
cd ..

# ========================================================================
# mathlibs, with MPI
# ========================================================================

cd mathlibs

# do not try to compile MPI code, will fail anyway
sed 's/acx_mpi_try_c_compile=yes/acx_mpi_try_c_compile=no/g' ./configure -i

# needed for the MS MPI compilation
export FFLAGS=-fno-range-check

# direct configure with the MPI settings
./configure --with-mpi=yes --with-mpi-dir=$HOME/elmer_source/msmpi --with-mpi-lib-dir=$HOME/elmer_source/msmpi/Lib/amd64 --with-mpi-inc-dir=$HOME/elmer_source/msmpi/Inc --with-mpi-library=-lmsmpi --prefix=$HOME/ElmerMPI --host=x86_64-w64-mingw32
make
make install

cd ..

# ========================================================================
# elmergrid, meshgen2d, eio, hutitter
# ========================================================================

cd elmergrid
./configure --prefix=$HOME/ElmerMPI --host=x86_64-w64-mingw32
make
make install
cd ..

cd meshgen2d
./configure --prefix=$HOME/ElmerMPI --host=x86_64-w64-mingw32
make
make install
cd ..

cd eio
./configure --prefix=$HOME/ElmerMPI --host=x86_64-w64-mingw32
make
make install
cd ..

cd hutiter
./configure --prefix=$HOME/ElmerMPI --host=x86_64-w64-mingw32
make
make install
cd ..


# ========================================================================
# ElmerSolver, with MPI
# ========================================================================

cd fem

# do not try to compile MPI, will fail anyway
sed 's/acx_mpi_try_c_compile=yes/acx_mpi_try_c_compile=no/g' ./configure -i
# dirty trick to skip this particular section of configure
sed 's/  test "$cross_compiling" = yes &&/  test "$cross_compiling" = no &&/g' ./configure -i
# needed because of (indirect) dependencies on mpi library
sed 's/ EXTRA_LIBS="-L. -L$prefix\/lib -lelmersolver"/ withval=$with_mpi_lib_dir; mpi_lib_dir="$withval";EXTRA_LIBS="-L. -L$prefix\/lib -lelmersolver -L$mpi_lib_dir -lmsmpi -static-libgcc -static-libgfortran"/g' ./configure -i

# needed for the MS MPI compilation
export FFLAGS=-fno-range-check
export FCFLAGS=-fno-range-check

# do static compile, so we don't need libgfortran-3.dll etc dependencies in windows
export LDFLAGS='-static'

./configure --with-mpi=yes --with-mpi-dir=$HOME/elmer_source/msmpi --with-mpi-lib-dir=$HOME/elmer_source/msmpi/Lib/amd64 --with-mpi-inc-dir=$HOME/elmer_source/msmpi/Inc --with-mpi-library=-lmsmpi --prefix=$HOME/ElmerMPI --host=x86_64-w64-mingw32

# first compile as far as it gets
# -static means we also need the libelmersolver.dll/libelmersolver.a
# so it will stop at the linking process

make

# now prepare the libelmersolver.dll, just like msmpi.dll
cd src
gendef libelmersolver.dll
x86_64-w64-mingw32-dlltool -d libelmersolver.def -l libelmersolver.a -D libelmersolver.dll
cd ..

# and the final compile
make
make install

cd ..


# done with compiling
# now transfer to Windows, any directory will do
# and copy libelmersolver.dll from the lib directory to the bin directory
# or set the library env variables accordingly
#
#
# the mpi-version is run by, e.g. on four cores
# first decompose mesh using ElmerGrid:
# ElmerGrid 2 2 . -metis 4
# then run from cmd:
# mpiexec -n 4 ElmerSolver_mpi.exe
#

david_coe
Posts: 7
Joined: 13 Feb 2014, 11:08
Antispam: Yes

Re: instructions for compiling Elmer on windows

Post by david_coe »

Many thanks, Anton!

That's put the last major piece in for a Windows 64bit-clean Elmer - it works too! I'd already found the Symscape note on cross-compiling MSmpi with MinGW but would never have worked out the need to tweak libelmersolver.dll as well.

Nice touch, using sed instead of emacs+diff+patch. Apologies all for not spotting the upload attachment widget.

--
David
Post Reply