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

stdlib_io_npy, FPM and Rank > 4 #796

Open
RJaBi opened this issue Apr 12, 2024 · 5 comments
Open

stdlib_io_npy, FPM and Rank > 4 #796

RJaBi opened this issue Apr 12, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@RJaBi
Copy link

RJaBi commented Apr 12, 2024

Description

When I use stdlib_io_npy via FPM, i.e. with

[dependencies]
stdlib = { git="https://github.com/fortran-lang/stdlib", branch="stdlib-fpm" }

the FPM defaults to building with maximum rank of 4 for array procedures. While I can see that there are instructions for building with cmake to set this higher (up to 15), I'm running in a cluster environment where I'm having a few issues with cmake suddenly while FPM basically just works.

Except that I need rank 7. Is there a way in the FPM toml or environment variable to set -DCMAKE_MAXIMUM_RANK to 7 instead?

Expected Behaviour

The preprocessor generates array procedures with up to rank 7 when using the FPM.

Version of stdlib

c673e3b

Platform and Architecture

SUSE Linux Enterprise Server 15 SP4

Additional Information

I have some binary data U which is naturally rank 7, double precision complex. I need to convert this to a different format for use in other code but the code to do this is in python. I have reader code in Fortran that I know gives me the correct ordering. I was going to use this fortran code to read the data, dump it to numpy so I can read it into python and then output it again there. This way, I could be assured that I had not messed up the ordering of the data.

The stdlib function I was to use was save_npy and so hence a MWE would be

program example_savenpy
  use stdlib_io_npy, only: save_npy
  implicit none
  real :: x(3, 2, 4, 4, 4, 4, 4) = 1
  call save_npy('example.npy', x)
end program example_savenpy

but of course the difficulty is in the FPM build.

@RJaBi RJaBi added the bug Something isn't working label Apr 12, 2024
@jvdp1
Copy link
Member

jvdp1 commented Apr 12, 2024

You can build locally a version of stdlib with up to rank 7 as described here. This would need to first modify the variable maxrank in fpm-deployment.sh.

@jalvesz is working on an alternative Python script (see #791 for more details). Unfortunately I didn't get a chance to test it. Don't hesitate to provide feedback in #791 too.

@RJaBi
Copy link
Author

RJaBi commented Apr 15, 2024

Thanks! I'll have a look and see how I get on.

Unfortunately the computer I want to use is down for a few days, so it'll take a little time.

@RJaBi
Copy link
Author

RJaBi commented Apr 25, 2024

I was able to use #791 to generate a pre-processed version with the approriate max rank and add that dependency as

[dependencies]
stdlib = {path = 'temp/stdlib/stdlib-fpm/'}

which seems to work (it compiles at least which I suspect will do the trick as I'm not asking for anything complicated).

I did however stumble across something else that may have been appropriate, but can't find it now. In the fpm.toml of stdlib on the stdlib-fpm branch there is

[preprocess]
[preprocess.cpp]

and FPM documentation suggests that this could be modified in the dependencies of another project, i.e.

[dependencies]
fftpack = { git="https://github.com/fortran-lang/fftpack.git", preprocess.cpp.macros = ["REAL32"] }

At some point, I saw the maxrank in there for the stdlib preprocess, but I can't find the exact form for it now. Clearly being able to do

[dependencies]
stdlib = { git="https://github.com/fortran-lang/stdlib", branch="stdlib-fpm",  preprocess.cpp.macros = ["DMAXRANK=7"]}

Would be a neat way to do what I need. Like I say, I can't find that now though (the above line does not work).

@jalvesz
Copy link
Contributor

jalvesz commented Apr 27, 2024

@RJaBi glad to know the script was useful to you! as this an early stage proposal your feedback is highly useful to consider before pushing further with it.

In your comment #791 (comment) you mention not being able to use Cray compilers, I have personally never worked with them (and have no means to). So I was wondering if on your system are you able to set the environment variables FPM_FC, FPM_CC and FPM_CXX to point to the Cray compilers before building?

Clearly being able to do

[dependencies]
stdlib = { git="https://github.com/fortran-lang/stdlib", branch="stdlib-fpm",  preprocess.cpp.macros = ["DMAXRANK=7"]}

Would be a neat way to do what I need.

This is an interesting use case which I did not think about when working out the script, as the main target was to preprocess stdlib in-place. I think that to enable what you want to do, fpm should be able of handling fypp on its own to recursively apply fypp preprocessing to a project and any dependencies within.

@RJaBi
Copy link
Author

RJaBi commented Apr 29, 2024

...able to set the environment variables FPM_FC, FPM_CC and FPM_CXX to point to the Cray compilers before building?

Yes I can set these. If I do, than the script crashes at the line:
flags = preprocessor[FPM_FC]

as there is no crayftn entry in the preprocessor variable. I think that the appropriate flag is just '-c', but I'm not 100% sure. This still doesn't make it compile, but that's cause the cray compiler is very picky (I think the error might be related to a variable called module) and not a problem with your script.

Yes, that's clearly a FPM thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants