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

Memory mapped features #765

Open
PierUgit opened this issue Jan 30, 2024 · 9 comments
Open

Memory mapped features #765

PierUgit opened this issue Jan 30, 2024 · 9 comments
Labels
idea Proposition of an idea and opening an issue to discuss it

Comments

@PierUgit
Copy link
Contributor

PierUgit commented Jan 30, 2024

Motivation

Provide some memory mapped file features to Fortran. These features are indeed accessible througt the C interoperability, but the idea here is to encapsulate them to get an easy to use interface, with additional runtime checks. Two meain usages:

  • allocating arrays that are potentially bigger the RAM+swap size, and are which are backed in a temporary file (anonymous mapping)
  • opening existing files or creating new files, and mapping them to arrays

Prior Art

Searching "memory mapped files Fortran" in Google returns results that all use the C interoperability of C/posix features, or Windows specific routines with the Intel compiler. A stdlib implementation should have the OS dependent code under a unique interface.

Additional Information

This was originally discussed on the Fortran Discourse, where the inclusion in stdlib has been suggested.

I have prepared a small demonstration code to show what it could look like (C/posix stuff only): https://github.com/PierUgit/fmmap/tree/main

@PierUgit PierUgit added the idea Proposition of an idea and opening an issue to discuss it label Jan 30, 2024
@jvdp1
Copy link
Member

jvdp1 commented Feb 4, 2024

Thank you @PierUgit for this suggestion.
The Discourse discussion is interesting and it seems that there is interest for such an implementation.
My main fear is that such an implementation will be OS-dependent, which may result in issues with portability. However, it should not stop such a projet. I think it would be a nice addition to stdlib.

@PierUgit
Copy link
Contributor Author

PierUgit commented Feb 4, 2024

It's definitely OS-dependent, and even worse maybe compiler-dependent. I assume that on Posix systems all compilers will provide the mmap features, but on Windows I don't know. The Intel compiler directly provides some routines in the kernel32 module, but I'm not sure how it goes with other compilers... I do not develop at all on Windows, so I'm a bit lost at that point.

Generally speaking, how are managed the OS dependent features in stdlib? Are there any in the existing code base? Are there available macros?

@jvdp1
Copy link
Member

jvdp1 commented Feb 8, 2024

I do not develop at all on Windows, so I'm a bit lost at that point.

Me neither...

Generally speaking, how are managed the OS dependent features in stdlib? Are there any in the existing code base? Are there available macros?

Currently only stdlib_system is compiled depending on the OS (with a CPP macro _WIN32). But it gives some issues (e.g., #738).
fpm is probably more advanced regarding OS-dependencies.

@PierUgit
Copy link
Contributor Author

PierUgit commented Feb 8, 2024

I will try porting the demo code to Windows and see... I have to set up a dev environment on my multimedia mini-PC first (the one that sits below the TV, as this is the only Windows machine around :D)

@arjenmarkus
Copy link
Member

arjenmarkus commented Feb 9, 2024 via email

@PierUgit
Copy link
Contributor Author

PierUgit commented Feb 9, 2024

An example code (even with some dust :)) could definitely help. And you're also welcome if you want to help.

@arjenmarkus
Copy link
Member

arjenmarkus commented Feb 12, 2024 via email

@PierUgit
Copy link
Contributor Author

I could install the MSYS2 environment on my office laptop, and start porting the code to Windows. I have a rough version of the anonymous mapping and it looks OK, so at the end everything should (hopefully) work.

Please find the zip file in the attachment (hoping that it is accepted) -- oops, that is not the case, well, I had to rename the two batch files, then it worked.

Actually there's no attachment in the GitHub interface, where I'm reading the posts. I am sending you a separate and personal email : could you send again the files in the answer?

@PierUgit
Copy link
Contributor Author

The code now runs on Windows :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea Proposition of an idea and opening an issue to discuss it
Projects
None yet
Development

No branches or pull requests

3 participants