docbrown1955 / marty-public

Calculation of tree-level and one-loop Feynman diagrams Beyond the Standard Model
https://marty.in2p3.fr
GNU General Public License v3.0
18 stars 5 forks source link

Improving group_g.h in the numerical library #77

Open marco-palmiotto opened 1 month ago

marco-palmiotto commented 1 month ago

Hi, I noticed that, on large numerical libraries (such as the one I use for the MSSM), compilation is really long and resource-intensive in every file which has group_g.h included. I found out that it contains the definition of a variable which maps strings to functions (or something alike). Therefore, in libraries with lots of functions, this variable, defined inline, causes the slow-down of compilation. I adapted the file by hand in my project, defining the variable as external:

#ifndef CSL_LIB_mssm2to2_G_H_INCLUDED
#define CSL_LIB_mssm2to2_G_H_INCLUDED

#include <array>
#include "common.h"
#include "librarytensor.h"
#include "callable.h"
#include "csl/initSanitizer.h"
#include "params.h"
#include "func_mssm2to2.h"

namespace mssm2to2 {

extern const std::array<Callable<complex_t, param_t>, 3456> f_G;

}
 // End of namespace mssm2to2

#endif

with the definition of f_G copied in group_g.cpp.

It would be nice to have this as the default setup, to help compilation time of each project :) I can do it myself if I know which file to edit :P

docbrown1955 commented 1 week ago

@marco-palmiotto Good idea! It was declared inline for simplicity, but indeed we can change it if it causes performance issues.

The code generating libraries is in csl and can be modified quite easily, it is mostly files starting with the library prefix responsible of outputing all the library and converting csl::Expr into executable C code.

I can pin-point the exact function generating the function map: https://github.com/docbrown1955/marty-public/blob/4d5697473526149debe830648590b8de29ed59fe/src/csl/librarygroup.cpp#L334

The simplest solution is probably to add a is_header parameter in the LibraryGroup::printFunctionStack() method, which will make it print the declaration or definition (reusing the existing code). The method is called from here: https://github.com/docbrown1955/marty-public/blob/4d5697473526149debe830648590b8de29ed59fe/src/csl/librarygenerator.cpp#L930

It seems straigth-forward to add a boolean parameter in the existing call of LibraryGroup::printFunctionStack() and add another call in the source file generation a few lines below.

Don't hesitate if you have any question :)

docbrown1955 commented 1 week ago

To be just a bit more specific, in LibraryGenerator::printGroup():

  file header(path + "/" + incDir + "/" + nameHeader);
  ...
  g.printFunctionStack(header, 0, true);
  ...

  file source(path + "/" + srcDir + "/" + nameSource);
  ...
  g.printFunctionStack(source, 0, false);
  ...

A few details: