Palabos full compilation

Hello there !

I am trying to use Palabos in my software project involving other libraries as well, and I can’t get a single makefile project working because of undefined references. As far as I understand, I miss several Palabos libraries.

I would like to know if there is a way to compile the whole Palabos libraries files at once, so I could copy them up in system-wide directories (such as /usr/local/palabos), which will allow others users of my system to use Palabos in their Makefiles easily.

I am not very familiar with the SConstruct way of doing, so any hint will be appreciated.

Thanks in advance

Hi,

Yes, you can compile Palabos at once and install it on a system-wide basis, manually (we should probably automate this at some point, but for now it turns out that most users appreciate the fact that Palabos simply compiles locally after typing “make”, and they don’t need to think about libraries, path variables, and stuff like this).

Here’s how you can proceed:

  1. Place the Palabos source code wherever you want on your system (let’s call this $TMP_PALABOS)
  2. Go to any of the example directories, for example $TMP_PALABOS/examples/showCases/cavity3d/. Edit the Makefile and adjust the option to choose between the mpi-parallel and the non-parallel version. Note: you can have both the parallel and the non-parallel libraries at the same time by repeating steps 2&3, once for either version. This is possible, because the libraries created in either case don’t have the same name. But then again, I’d say that it’s easier to just compile with MPI and use this library for both parallel and non-parallel runs.
  3. Type “make”. This will automatically create the libraries and place them in the directory $TMP_PALABOS/lib/.
  4. Copy the whole directory tree of Palabos do a system-wide location (ex.: /usr/local/palabos/ which from now on I will call $PALABOS_ROOT). You can erase the examples directory if you want, but you should keep all the rest, because users will need both the libraries in the sub-directory lib/ and the include files in the sub-directories src/ and externalLibraries/ .

Now, people can compile C++ programs with Palabos by including


#include "palabos2D.h"
#include "palabos2D.hh"

for 2D applications, and


#include "palabos3D.h"
#include "palabos3D.hh"

for 3D applications. The following compiler options are needed:


-DPLB_USE_POSIX -I$PALABOS_ROOT/src -I$PALABOS_ROOT/externalLibraries

and, to link against the Palabos libraries, you will need the following options if you use the non-parallel version:


-L$PALABOS_ROOT -lplb

or the following options if you use the parallel version:


-L$PALABOS_ROOT -lplb_mpi

Btw, please let us know if this worked or not, it’s always good to know…

jlatt Wrote:

Btw, please let us know if this worked or not,
it’s always good to know…

I have done as you told me and it worked quite fine (I can share my Makefile if you want). I have not yet tested it with MPI though. Anyway, thanks for your advice :slight_smile:

As usual I have spoken too fast … (or maybe not). I am so sorry to require your help so much ^^.

The compilation stage went fine either with MPI enabled or not. But errors appeared when I tried to split the code using palabos in several files.

Let’s say I have 2 files, main.cpp and function.cpp which look like this
main.cpp :


#include "palabos2D.h"
#include "palabos2D.hh"
void aFunction(plb::MultiBlockLattice2D<...>) ;
int main( int argc, char** argv) {
  // ...
  aFunction(lattice)
}

function.cpp :


#include "palabos2D.h"
#include "palabos2D.hh"
void aFunction(plb::MultiBlockLattice2D<...> lattice) {
  initializeAtEquilibrium(lattice, ... ) ;
}

As far as I understand, the palabos2D.h includes the palabos usual library declarations and the palabos2D.hh the templates declaration and definitions (since you cannot separate them with templates).
Tough, the linker trows out errors due to ‘multiple definitions’, mainly in core/blockIdentifiers.hh.

If I remove the #include “palabos2D.hh” from functions.cpp, these error messages dissapears but the linker complains about undefined reference to initializeAtEquilibrium. Which is normal, because the template function needed is not instanciated in function.o (which now lacks the template definitions in palabos2D.hh), nor in main.o (which does not call this function at all).

So the only workaround is to instanciate the template function in main.cpp like this.

main.cpp :


#include "palabos2D.h"
#include "palabos2D.hh"
void aFunction(plb::MultiBlockLattice2D<...>) ;
namespace plb{
  template initializeAtEquilibrium<some types>(...);
}
int main( int argc, char** argv) {
  // ...
  aFunction(lattice)
}

function.cpp :


#include "palabos2D.h"
void aFunction(plb::MultiBlockLattice2D<...> lattice) {
  initializeAtEquilibrium(lattice, ... ) ;
}

Still, I think that this is probably not like this that it was meant to be done. Am I missing something, or is it the way the library is designed that causes this behaviour ?

Thanks in advance :slight_smile:

To be more precise, the ‘multiple definitions’ problems comes from template specialization functions, which the compiler handles differently than generic templates functions.

So the errors occurs in .hh files where there are specialized functions, like in core/blockIdentifiers.hh.

After several tries, there are 2 others workarounds to this :

  • commenting out the specialized template functions from the .hh header file, copy them in a .cpp file that you compile and link with your files.
  • declare each specialized template function inline

I don’t know if there is a better solution yet. Grep-ing and inserting inline in the two .hh (namely core/blockIdentifiers.hh and /libraryInterfaces/TINYXML_xmlIO.hh) files containing specialized functions seemed to do the job, but I do not know if this solution is a Good Thing (maybe the inline-hack is gcc-specific, therefore not portable), or if there is a better one.

Sorry again for noisying your forum. :slight_smile:

Hi Louen,

Thanks for your remarks; this is definitely signal, and no noise, because it’s a good starting point for us to provide, at some point, a system-wide installation process.

The problem you are pointing out turns out to be a bug in Palabos, which we have never noticed because all our test cases are written within a single .cpp file …

Your solution of declaring all conflicting functions inline is, to my knowledge, standard compliant and therefore acceptable. Another solution is to move these functions from the .hh file to a .cpp file. I did this right now and produced a corresponding new release (v0.6 r2).

Would it be possible for you to quickly test this new release, and see if it solves all your problems?

Thanks in advance.

Changing between old an new release gave no problem. Everything compiled fine.

So now, the 2 files I mentioned are now .cpp files. If I am understand correctly, the template-specialized functions are now compiled into libplb.a and included with my executable at link-time, instead of being included my cpp files and compiled into objects files, right ?

I do not know much of the internals of palabos to tell if changing release had an effect on the programs yet ( I’m still writing ‘dummy’ programs to understand how it works. But still it seems to work - at least to compile ^^).

Thanks for your help, and feel free to ask me any question if something seems unclear :slight_smile:

Hello,

I am happy to hear that this now works; I think we will summarize this procedure in the user’s guide, for other people who wish to make a system-wide installation.

To answer your question, no, the templates are not specialized/precompiled in your case. You are still including the full template code in end-user applications, which explains why the compilation of end-user applications is quite slow. The library libplb.a just contains those parts of Palabos that are not template dependent (for example, the xml parser or the load-balancing algorithm are non-templates, so they are compiled like in a traditional C++ program).

Ok, Thanks for your explanations :slight_smile:

Maybe if you want to allow easy system-wide installation you should provide a “root” makefile or script that would automate this process for lazy systems admins like me :slight_smile:

Anyway, thanks for your quick help and support !