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

Idea: support different real and complex kinds #14

Open
hsnyder opened this issue Sep 9, 2021 · 8 comments · May be fixed by #27
Open

Idea: support different real and complex kinds #14

hsnyder opened this issue Sep 9, 2021 · 8 comments · May be fixed by #27

Comments

@hsnyder
Copy link
Contributor

hsnyder commented Sep 9, 2021

It looks like FFTPACK has "double precision" hard coded in. Would the maintainers be open to accepting a pull request that made this configurable? I would:

  • change all instances of "double precision" to "real(rk)" and do the same for complex
  • add a new file, that contains "integer, parameter :: rk = kind(1.0d0)"
  • include that new file in all the old fortran77 files, so that the kind being used could be changed at compile time in exactly one place.

We could use a module instead of "include", but I'm not familiar enough with old-style loose functions to know if that would work.

The end result would be that the functions are still only provided for one kind, but rather than that kind being hard-coded to double precision, the user could choose the kind themselves. And just to be clear, I'm offering to do this, not requesting that someone else do it (though that's fine too, of course).

So what do we think? Does that involve too many changes to the old code? Or is it ok?

@certik
Copy link
Member

certik commented Sep 9, 2021

I think that works and is a good idea.

@zoziha
Copy link
Contributor

zoziha commented Sep 10, 2021

I also think this is a good idea. This approach, I believe, has a certain amount of work, but it's okay.
Maybe we can change the kind of fftpack like this in the future until we have a Fortran Generics solution:

module fftpack_kind
 #if defined(SP)
     integer, parameter :: rk = sp
 #elif defined(QP)
     integer, parameter :: rk = qp
 #else
     integer, parameter :: rk = dp
 #endif
end module fftpack_kind

For the fpm command:

fpm build --flag "-DSP"

@zoziha zoziha pinned this issue Sep 10, 2021
@certik
Copy link
Member

certik commented Sep 10, 2021

@zoziha great idea. I was wondering about precisely this point.

@zoziha zoziha mentioned this issue Sep 12, 2021
@jacobwilliams
Copy link
Member

Another option: use something like what I describe here: https://fortran-lang.discourse.group/t/library-exporting-interface-for-multiple-real-kinds/2686 to provide all the interfaces simultaneously. Is that useful for some applications? IDK.

@arjenmarkus
Copy link
Member

arjenmarkus commented Jan 31, 2022 via email

@zoziha zoziha linked a pull request May 7, 2022 that will close this issue
@zoziha
Copy link
Contributor

zoziha commented May 27, 2022

There is another way to support multiple precision:

  1. Use real to define real number instead of real(dp), and not explicitly define real number kind will make fftpack use the default real number kind, usually real32;
  2. Compilers generally provide options to change the default real number kind, such as gfortran's -fdefault-real-8

@arjenmarkus
Copy link
Member

arjenmarkus commented May 27, 2022 via email

@jacobwilliams
Copy link
Member

This is what I do in my codes:

    module splpak_module

    use iso_fortran_env

    implicit none

    private

#ifdef REAL32
    integer,parameter :: wp = real32   !! Real working precision [4 bytes]
#elif REAL64
    integer,parameter :: wp = real64   !! Real working precision [8 bytes]
#elif REAL128
    integer,parameter :: wp = real128  !! Real working precision [16 bytes]
#else
    integer,parameter :: wp = real64   !! Real working precision if not specified [8 bytes]
#endif

    integer,parameter,public :: splpak_wp = wp   !! Real working precision

...

That way wp (or rk or whatever) can be a private variable used in the module. Then fftpack_wp is exported (we don't want to export the two-letter version for fear of namespace collisions. I think the explicit REAL32, etc is better than just SP, etc for the preprocessor directives.

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

Successfully merging a pull request may close this issue.

5 participants