Skip to content

Change Memory layout of positions from Fortran- to C-contiguous  #2210

@zemanj

Description

@zemanj

Is your feature request related to a problem? Please describe.
Currently, all functions that operate (especially in-place) on atom positions obtain a copy of atom positions via AtomGroup.positions, regardless of whether positions are modified in- or out-of-place, or they are merely input data that is not altered. In some (if not many) cases, a tremendous speed-up could be achieved if the respective functions could obtain a view instead of a copy of an AtomGroup's positions. At the moment, this is not possible for two reasons:

  1. AtomGroup.positions gets its data from Universe.trajectory.ts.positions via fancy indexing, and fancy indexing means copying.
  2. More importantly, Universe.trajectory.ts.positions refers to coordinates.base.Timestep._pos, which is a Fortran-contiguous array. Therefore, potentially obtained views of that array are unsuitable for use with C-level functions.

Describe the solution you'd like
Change coordinates.base.Timestep.order from 'F' to 'C' and provide a way of obtaining a (if possible, C-contiguous) view of an AtomGroup's positions.

Describe alternatives you've considered
Invent computers with two-dimensional main memory...

Additional context
Two candidates that come to my mind in terms of speed-up are *Group.center*() and *Group.wrap()
when the index array *Group.atoms.ix is a (contiguous) range.

A possible drawback of changing the positions/velocities/forces memory layout is that reading and (probably to a lesser extent) writing of DCD trajectories will be a bit slower since DCD stores positions etc. as Fortran-contiguous arrays.

If you have any additional concerns, please let me know!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions