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

Inlining of elemental functions with argument(s) being array (slices) #400

Open
MichaelSt98 opened this issue Oct 14, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@MichaelSt98
Copy link
Collaborator

What happened?

Compile error, as a scalar variable can't be assigned to some array value ...

What are the steps to reproduce the bug?

Problem being:

elemental function elem(x, y)
    real :: x, y, elem, tmp
    temp = y * 2.0
    elem = x + tmp
end function elem

This function can be called

* with `x` and `y` being scalars
* with `x` and `y` being arrays of the same shape
* with `x` or `y` being an array and the non-array being a scalar

Thus, e.g.:

```fortran
real :: x_scalar, b_scalar, res_scalar
real :: x_arr(10). y_arr(10), res_arr(10)
real :: x_arr_2(12). y_arr_2(12), res_arr_2(12)

res_scalar = elem(x_scalar, y_scalar)
res_arr = elem(x_arr, y_arr)
res_arr = elem(x_arr, y_scalar)
res_arr = elem(y_scalar, x_arr)
res_arr_2 = elem(x_arr_2, y_arr_2)
...

A quick solution is not possible, since:

  • adapting/adding the dimensions to the result var is not sufficient, since temporaries within the elemental function potentially need to be promoted as well
  • as shown above the same routine can be called in various ways influencing the inlining

The potential solution probably should

  • use a loop instead of vector notation to inline (to simplify the problem with promoting (some of) temporaries, ... in the end this could help us to solve it without need for (sophisticated) dataflow and dimension analysis)
  • reuse variables/temporaries (maybe introduce _scalar and _array versions of temporaries (and result)

Version

main

Platform (OS and architecture)

Mac / HPC2020

Relevant log output

No response

Accompanying data

No response

Organisation

No response

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

1 participant