<div dir="ltr"><div dir="ltr">On Fri, Jan 17, 2020 at 7:00 AM Lars Odsæter <<a href="mailto:lars.odsater@sintef.no">lars.odsater@sintef.no</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">




<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Dear PETSc users,</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
First, thanks to the developers for your great effort with the PETSc library, which I have benefited from several times. </div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
I want to share with you that I recently was able to cross compile PETSc with the MXE (mxe.cc) cross compiler, and then link it into an application (also built with the mxe compiler) to produce an executable that I successfully ran on my Windows computer. In
 doing this I realized that there is very little documentation of this on the web, so maybe others could benefit from my approach. It contains a few hacks that might be solved more elegant, but that is probably out of may range.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
First, I installed the mxe cross compiler following the tutorial (<a href="https://mxe.cc/#tutorial" target="_blank">mxe.cc/#tutorial</a>):</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span>git clone <a href="https://github.com/mxe/mxe.git" target="_blank">https://github.com/mxe/mxe.git</a><br>
</span>
<div>make cc<br>
</div>
<span>make blas lapack</span><br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span>export PATH=~/code/mxe/usr/bin:$PATH<br>
</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span><br>
</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span>Then I compiled PETSc (3.11.3 tarball):</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span><br>
</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span><span>wget <a href="http://ftp.mcs.anl.gov/pub/petsc/release-snapshots/petsc-3.11.3.tar.gz" target="_blank">http://ftp.mcs.anl.gov/pub/petsc/release-snapshots/petsc-3.11.3.tar.gz</a><br>
</span>
<div>gunzip -c petsc-3.11.3.tar.gz | tar -xof -<br>
</div>
<div>cd petsc-3.11.3/<br>
</div>
<div>./configure PETSC_ARCH=arch-mxe-static \<br>
</div>
<div>  --with-mpi=0 --host=i686-w64-mingw32.static \<br>
</div>
<div>  --enable-static --disable-shared \<br>
</div>
<div>  --with-cc=i686-w64-mingw32.static-gcc \<br>
</div>
<div>  --with-cxx=i686-w64-mingw32.static-g++ \<br>
</div>
<div>  --with-fc=i686-w64-mingw32.static-gfortran \<br>
</div>
<div>  --with-ld=i686-w64-mingw32.static-ld \<br>
</div>
<div>  --with-ar=i686-w64-mingw32.static-ar \<br>
</div>
<div>  --with-pkg-config=i686-w64-mingw32.static-pkg-config \<br>
</div>
<span>  --with-batch --known-64-bit-blas-indices</span><br>
</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span><span><br>
</span></span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span><span>Next, I did the reconfigure step that was explained in the output from the call to configure:</span></span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span><span><br>
</span></span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span><span><span>* copy 'conftest-arch-mxe-static' to your Windows machine<br>
</span>
<div>* Rename it with extension '.exe'<br>
</div>
<div>* Run the application in Windows. This generates 'reconfigure-arch-mxe-static.py'<br>
</div>
<div>* Copy 'reconfigure-arch-mxe-static.py' back to the Linux machine<br>
</div>
<div>* Run the python script:<br>
</div>
<div><br>
</div>
<span>python reconfigure-arch-mxe-static.py</span><br>
</span></span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span><span><br>
</span></span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span><span>Now, 'make all' failed to compile, but I did two hacks to mitigate it:</span></span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span><span><br>
</span></span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif">1) In  '<span>~/code/petsc-3.11.3/arch-mxe-static/include/petscconf.h' include the following lines:<br>
</span>
<div>#ifndef PETSC_HAVE_DIRECT_H<br>
</div>
<div>#define PETSC_HAVE_DIRECT_H 1<br>
</div>
<span>#endif</span></span><br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif"><span><br>
</span></span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif"><span>2) <span>In ~/code/petsc-3.11.3/src/sys/error/fp.c, comment out line 405-406:<br>
</span>
<div>// elif defined PETSC_HAVE_XMMINTRIN_H                                          
<br>
</div>
<span>// _MM_SET_EXCEPTION_MASK(_MM_MASK_INEXACT | _MM_MASK_UNDERFLOW);</span></span></span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif"><span><span><br>
</span></span></span></div>
<div><font color="#000000" face="Calibri, Arial, Helvetica, sans-serif"><span style="font-size:12pt">After this 'make all' ran
</span>successfully<span style="font-size:12pt">. </span></font></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif"><span><span>I was finally able to compile my code (linking PETSc) following step 5 of the mxe tutorial: <a href="https://mxe.cc/#tutorial" style="margin:0px;font-family:Calibri,Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)" id="gmail-m_6335830823424149415LPlnk967654" target="_blank">mxe.cc/#tutorial</a></span></span></span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Then, simply copy to Windows and double-click.</div></div></blockquote><div><br></div><div>Great! It sounds like we can make a couple of fixes that make this easier:</div><div><br></div><div>1) Name the batch executable .exe for this</div><div><br></div><div>2) Find direct.h correctly</div><div><br></div><div>3) Do not find xmmintrin.h</div><div><br></div><div>Can you send me your configure.log so I can see what went wrong on the header location.</div><div><br></div><div>  Thanks,</div><div><br></div><div>     Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Best regards,</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Lars Hov Odsæter</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span><br>
</span></div>
</div>

</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>