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

Significantly reduce peak memory usage when vpacket logging is enabled #694

Merged
merged 2 commits into from
Jan 18, 2017

Conversation

ftsamis
Copy link
Member

@ftsamis ftsamis commented Jan 17, 2017

@Heringer-Epson attempted a run with

last_no_of_packets: 1.0e+6
no_of_virtual_packets: 5

on a system with 16GB of RAM (no swap) and got TARDIS killed by the OS just after the final iteration was finished.

Fix:
Instead of allocating numpy arrays for the virt_packet* arrays all at once, copying from the C arrays, and freeing the C arrays, simply transfer ownership of the C array memory to a numpy array object.

With this fix, peak memory usage by virt_packet arrays is reduced to half.

Instead of allocating numpy arrays for the virt_packet* arrays all
at once, copying from the C arrays, and freeing the C arrays, simply
transfer ownership of the C array memory to a numpy array object.

With this fix, peak memory usage by virt_packet arrays is reduced to half.
cdef extern from "numpy/arrayobject.h":
void PyArray_ENABLEFLAGS(np.ndarray arr, int flags)

cdef c_array_to_numpy(void *ptr, int dtype, np.npy_intp N):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a really small thing, but as we are using numpy API, I think we should use np.int_t dtype instead of int dtype.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we should do this. The numpy reference declares this as an int: https://docs.scipy.org/doc/numpy/reference/c-api.array.html#c.PyArray_SimpleNewFromData

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, then leave it.

@unoebauer
Copy link
Contributor

unoebauer commented Jan 18, 2017

Just tested it with tardis-example and the above stated settings for real and virtual packets in the spectral cycle (compiled with vpacket-logging and open-mp, run with 2 threads). Works like a charm and memory consumption does not increase after the spectral cycle is complete! Great job @ftsamis!

@wkerzendorf
Copy link
Member

very good!

@wkerzendorf wkerzendorf merged commit e8370f4 into tardis-sn:master Jan 18, 2017
@ftsamis ftsamis deleted the vpacket-memory-economy branch January 18, 2017 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants