flatironinstitute / finufft

Non-uniform fast Fourier transform library of types 1,2,3 in dimensions 1,2,3
Other
293 stars 77 forks source link

constexpr everything #487

Open DiamonDinoia opened 3 months ago

DiamonDinoia commented 3 months ago

We should constexpr everything available in c++17 as this allows to do part of the computation at compile time when the data is needed.

We should also add macros CPP_20_CONSTEXPR CPP_23_CONSTEXPR and have cmake use the latest available standard in compiling so that even malloc/free can be constexpr in that case. A lot of the planning phase might be executed at compile time when the users bake finufft in their code as a source, this can make a meaningful difference.

This can be done in #482 #483 as it requires some code rewrite anyway.

ahbarnett commented 3 months ago

First paragraph sounds good.

2nd paragraph I don't understand. The main planning overhead is FFT plan (if FFTW) plus binsort (type 1,2). Neither of those can be "executed at compile time" :)

On Wed, Jul 17, 2024 at 11:27 AM Marco Barbone @.***> wrote:

We should constexpr everything available in c++17 as this allows to do part of the computation at compile time when the data is needed.

We should also add macros CPP_20_CONSTEXPR CPP_23_CONSTEXPR and have cmake use the latest available standard in compiling so that even malloc/free can be constexpr in that case. A lot of the planning phase might be executed at compile time when the users bake finufft in their code as a source, this can make a meaningful difference.

This can be done in #482 https://github.com/flatironinstitute/finufft/pull/482 #483 https://github.com/flatironinstitute/finufft/pull/483 as it requires some code rewrite anyway.

— Reply to this email directly, view it on GitHub https://github.com/flatironinstitute/finufft/issues/487, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACNZRSQIKA6TLNKSUCP6UTDZM2EO7AVCNFSM6AAAAABLA4BQ56VHI2DSMVQWIX3LMV43ASLTON2WKOZSGQYTGOJSGI4DAOA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- *-------------------------------------------------------------------~^`^~._.~' |\ Alex Barnett Center for Computational Mathematics, Flatiron Institute | \ http://users.flatironinstitute.org/~ahb 646-876-5942

DiamonDinoia commented 3 months ago

This is the most common argument that comes up when talking about constexpr everything. The goal to have the compiler do as much as possible at compile time. Not using constexpr might defer at runtime things that can be precomputed.