Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

Thread safe reductions in mod files. #768

Open
nrnhines opened this issue Jan 29, 2022 · 1 comment
Open

Thread safe reductions in mod files. #768

nrnhines opened this issue Jan 29, 2022 · 1 comment

Comments

@nrnhines
Copy link
Collaborator

Calculation of the magnetic dipole has long been implemented with mod files with main calculation being

RANGE ri, ia, Q, ztan
POINTER pv, Qtotal

AFTER SOLVE {
    ia = (pv - v) / ri          : axial current: ri - axial resistance, pv - pointer to parent compartment voltage
    Q = ia * ztan             : contribution of  axial current of this compartment to magnetic dipole
    Qtotal = Qtotal + Q   : Qtotal is pointer to magnetic dipole of entire cell
}

Qtotal points to a range variable in a POINT_PROCESS inserted in the cell. That variable is recorded into a Vector, and at the end
of the simulation, the vectors for each cell are added together to give the total network dipole trajectory.

CoreNEURON reduces the simulation time relative to NEURON on x86_64 by a factor of two because of loop vectorization (using the intel compiler) but one must manually comment out _PRAGMA_FOR_VECTOR_LOOP_ in the translated dipole.cpp to get correct results.

So the question is twofold. What needs to be done so that Qtotal = Qtotal + Q is essentially atomic so that the above PRAGMA is safe and that there is chance of this working on GPU? Currently there is a PROTECT stmt but that is implemented for pthreads
and isn't quite right as Qtotal points to different memory locations in each cell.

The magnetic dipole calculation is reminiscent of LFP calculations but I don't think the rarity of the former justifies an independent internal implementation as is done with membane current. Also, the notion of a mod file reduction variable is generic and so, I think, justifies proper NMODL support, though calling it a POINTER is perhaps open. In this case the reduction variable, QTotal.q exists on a per cell basis but...

@nrnhines
Copy link
Collaborator Author

I see from https://www.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/optimization-and-programming-guide/vectorization/automatic-vectorization/using-automatic-vectorization.html that

Although sum is both read and written in every iteration, the compiler recognizes such reduction idioms, and is able to vectorize them safely.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant