Thanks for the hint.

I did a naive test and managed to use the same function with different typedefs. Basically, it is relied on that C has no name mangling while C++ has name mangling. Could this trick applies to PETSc? The files for the test are attached. The procedure for compilation is in the `main.cpp`

Best regards,

C.-Y. GAO

<<attachment: name-conflict.zip>>


On Apr 6, 2023, at 02:04, Matthew Knepley <knep...@gmail.com> wrote:

On Wed, Apr 5, 2023 at 1:59 PM gaochenyi14 <gaocheny...@163.com> wrote:
Hi,

I rely on PETSc to deal with real and complex sparse matrices of dimension 1e4 * 1e4 or above. I want to use real version when only real matrices are involved, to achieve better performance, and use complex version only when complex matrices get involved. But in the manual it says different versions can not be used at the same time. Can this restriction be circumvented? If not, where does the restriction come from?

It is possible to do this, but it is cumbersome. You would have to compile both versions of the library, dlopen() them, and get the symbols you need. A group at Purdue has done this, but it is involved.

We use typedefs to change between real and complex. It would not be difficult to allow storage in several types. However, prescribing how one type interactes with another, particularly when data is passed in or out, is challenging. This difficulty does not go away with templates since it is about type interaction, not polymorphism.

  Thanks,

     Matt
 
All the best,
C.-Y. GAO


--
What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.
-- Norbert Wiener


Reply via email to