MFlowCode / MFC

Exascale simulation of multiphase/physics fluid dynamics
https://mflowcode.github.io
MIT License
137 stars 60 forks source link

Fix integer overflow #354

Closed wilfonba closed 5 months ago

wilfonba commented 5 months ago

Description

Fixes integer overflow for simulations with more than 2^31 cells.

Type of change

Please delete options that are not relevant.

Scope

If you cannot check the above box, please split your PR into multiple PRs that each have a common goal.

sbryngelson commented 5 months ago

Something about some of these changes doesn't quite seem right to me (I could be wrong). For example, if you write int(p), this shouldn't do anything if p is already int. Likewise for other quantities.

wilfonba commented 5 months ago

int(p) casts an 8-byte integer p to a 4-byte integer. The MPI routines only accept 4-byte integers.

sbryngelson commented 5 months ago

int(p) casts an 8-byte integer p to a 4-byte integer. The MPI routines only accept 4-byte integers.

Got it - though I see a couple other ones, like for s_compute_finite_difference_coefficients.

wilfonba commented 5 months ago

I didn't change the integer types in simulation because the global cell count is never computed in simulation. s_compute_finite_difference_coefficients is used in both simulation and post_process and expects a 4-byte integer.

sbryngelson commented 5 months ago

I didn't change the integer types in simulation because the global cell count is never computed in simulation. s_compute_finite_difference_coefficients is used in both simulation and post_process and expects a 4-byte integer.

Does it not automatically up (or down) cast the input precision? That would make this much easier to maintain, otherwise every time one of the "special" variables (e.g., p) is used in both simulation and another code (pre/post process), the developer needs to know that they need to do int(p).

wilfonba commented 5 months ago

It does not automatically cast the inputs. I'll just make simulation use 8-byte integers for m, n, and p, then everything will be the same. The only reason I didn't was because adding all the casting in the MPI routines would be tedious.

sbryngelson commented 5 months ago

It does not automatically cast the inputs. I'll just make simulation use 8-byte integers for m, n, and p, then everything will be the same. The only reason I didn't was because adding all the casting in the MPI routines would be tedious.

How is this different than what you already did?

wilfonba commented 5 months ago

I'll just explain it at our meeting this afternoon. It'll be easier that way.