Hello, I have a couple of questions about createWithArray in petsc4py: 1) What is the correct usage for creating a standard MPI Vec with it? Something like this seems to work but is it right?: On each rank do: a = np. zeros(localSize) v = PETSc. Vec(). createWithArray(a,
ZjQcmQRYFpfptBannerStart
This Message Is From an External Sender
This message came from outside your organization.
 
ZjQcmQRYFpfptBannerEnd
Hello,

I have a couple of questions about createWithArray in petsc4py:

1) What is the correct usage for creating a standard MPI Vec with it? Something like this seems to work but is it right?:

On each rank do:
a = np.zeros(localSize)
v = PETSc.Vec().createWithArray(a, comm=PETSc.COMM_WORLD)

Is that all it takes?

2) Who ‘owns’ the underlying memory for a Vec created with the createWithArray method, i.e., who is responsible for managing it and doing garbage collection? In my problem, the numpy array is created in a Cython module where memory is allocated, and a pointer to it is associated with a numpy ndarray via PyArray_SimpleNewFromData and PyArray_SetBaseObject. I have a deallocator method of my own that is called when the numpy array is deleted/goes out of scope/whenever python does garbage collection. All of that works fine. But if I use this array to create a Vec with createWithArray what happens when the Vec is, e.g., destroyed? Will my deallocator be called? Or does petsc4py know that it doesn’t own the memory and won’t attempt to free it? I can’t quite figure out from the petsc4py code what is going on. And help would be appreciated.

Thanks very much.

Samar

Reply via email to