Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance issue on MacOS-10.13 #69

Closed
nbieberdorf opened this issue Feb 1, 2019 · 5 comments
Closed

Performance issue on MacOS-10.13 #69

nbieberdorf opened this issue Feb 1, 2019 · 5 comments

Comments

@nbieberdorf
Copy link

Hello,

I am a long-time FF++ user (developing .edp scripts to model solid mechanics problems), and I just installed FreeFem++ on a new MacOS-10.13. I am noticing a strange performance issue on my Mac compared to my old Windows7 PC, and my troubleshooting attempts are below. Note that I have installed FreeFem++ v3.61-1 on both Mac and Windows using the respective binary packages, and these troubleshooting attempts are all executed in serial.

When I run a .edp script that computes a simple addition problem 1e6 times (speed_test.edp below), the execution time is almost 3 seconds on my Mac, while on my Windows7 computer, execution is 0.1 seconds. Much much slower on my Mac.

// speed_test.edp
real cpu = clock();
int j;
for (int i;i<(1e6);i++)
{
  j = j+1;
}
cout << "~~~~~~~~~solve time = " << clock()-cpu << "~~~~~~~~~ "<< endl;

When I compile and run a C++ script with the same purpose (simple addition 1e6 times), the execution time is 0.004 seconds on my Mac, and 0.01 seconds on my Windows PC. Much faster on my Mac.

When I run a .edp script that re-computes a varf on a 100x100 mesh 1e4 times (ts.edp below), execution time is ~45 seconds on my Mac, and ~55 seconds on my Windows PC. If I reduce the mesh size to 25x25, and run the same varf calculation 1e4 times, execution time is ~3.5 sec on my Mac and ~4.0 sec on my Windows PC. A bit faster on my Mac. (I found this script on a previous FF++ forum, and altered slightly to test performance)

// ts.edp
load "MUMPS_seq"
real cpu = clock();
func f = 1.0;
mesh Th = square(100,100);
// mesh Th = square(25,25);
real T = 1., dt = .1;
int nt = floor(T/dt), m;
fespace Vh(Th,P1);
Vh u=0;
varf vheat(u,v) =
int2d(Th)(u/dt*v+dx(u)*dx(v)+dy(u)*dy(v))
+ int2d(Th)(f*v) + on(1,2,3,4,u=0);
varf vmass(u,v) = int2d(Th)(u*v/dt);

real[int] b0=vheat(0,Vh);
real cpu0=clock();
matrix A = vheat(Vh,Vh,solver=UMFPACK);
cout << "  build un factorize = " << clock()-cpu0 << endl;;
matrix M = vmass(Vh,Vh,solver=UMFPACK);
cout << "  time before loop = " << clock()-cpu << endl;;

for (m=0;m<1e4;++m)
 {
  real[int] b=b0;
  b+= M*u[];
  real cpu=clock();
  u[] = A^-1*b;
}

Basically, execution is faster on my Mac when using the C++ loop script and the FF++ mesh varf script, as expected. However, when accomplishing simple addition, the Mac is remarkably slower than my Windows PC. My solid mechanics scripts use many looped calculations, and as a result their performance on my Mac is quite poor.

Note my Mac CPU is 6-core Intel Xeon E5, 3.5 GHz, 16 GB memory. My Windows CPU is 4-core Intel i7, 2.7 GHz, 8 GB memory. I should also point out that I installed FreeFem++ on a friend’s Mac (similar specs), using binary installation, and found the same performance issue.

Is there a way I can specify compilers, optimization flags, etc. within the FreeFem++ executable, to enhance performance? Do I need to install FreeFem++ from scratch using the compilation files to achieve good performance on a Mac? I have not found other FF++ forum posts discussing this problem, so my problem seems very strange.

Please let me know if you have any suggestions, or need further information.

Thanks,
Nathan

@nbieberdorf
Copy link
Author

Following up on this issue - can someone please provide some guidance? Should I expect slow performance when installing FF++ on Mac using the binary package?

Thanks

@prj-
Copy link
Member

prj- commented Feb 13, 2019

You are comparing apples and oranges here. What are you exactly interested in: performance of your loops in the .edp, or in the .cpp? My general advice is to do as little as possible in your .edp, and offload as much computation as possible in your .cpp.

@frederichecht
Copy link
Contributor

I know diff of speed between windows and unix (mac and linux)
I think this is due to the generation of code under windows.
To day no ways to solve.

@nbieberdorf
Copy link
Author

Thank you for the advice. I have been trying to couple my code with a c++ script, following the Dynamical Link example in Appendix C of the FF++ doc. I assume this will allow me to use a .edp script to call upon a (much faster) precompiled c++ script for mesh node calculations.

To learn, I wish to replicate the myfunction example from the doc., by compiling/linking myfunction.cpp myself (using the ff-c++, g++ commands in the doc). I found myfunction.cpp from some source code, along with ff++.hpp and dependencies (they are not included in the binary installation). I can compile and link myfunction.cpp without error, but I get the following error when executing load.edp:

load error : myfunction fail : dlerror : dlopen(/usr/local/ff++/openmpi-2.1/lib/ff++/3.61-1/lib/mpi/myfunction.dylib, 1): Symbol not found: __Z8map_typeB5cxx11 Referenced from: /usr/local/ff++/openmpi-2.1/lib/ff++/3.61-1/lib/mpi/myfunction.dylib Expected in: flat namespace in /usr/local/ff++/openmpi-2.1/lib/ff++/3.61-1/lib/mpi/myfunction.dylib

I suspect that I made a mistake when coordinating the ff++.hpp file and all its dependencies. Do you have a working example (with all the necessary files) of how to compile and link a c++ file to be called in FF++?

Once I can recreate a working example, I think moving all heavy computation from my .edp to a c++ script will be trivial.

Thank you,
Nathan

@prj-
Copy link
Member

prj- commented Mar 1, 2019

Using ff-c++ from a bundled FreeFem++ installation requires you having exactly the same configuration as when the bundle was created. It appears you are using a rather old FreeFem++ installation (3.61-1), and it is highly likely your configuration has evolved. Once you start using that kind of developer oriented feature, my advice is to compile FreeFem++ yourself. You can also first try to just add the -std=c++11 argument in your ff-c++ command line, but I can't assure you this will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants