"Smith, Barry F." <bsm...@mcs.anl.gov> writes:

>> There is some nontrivial infrastructure that would be needed for this
>> model.
>> 
>> 1. This new component needs to be built into a new library such as
>>   libpetsc-plugin.a (when static).
>> 
>> 2. Users need to know when they should link this module.  They'll need a
>>   link line something like -lpetsc-plugin -lslepc -lpetsc in this case.
>>   It would need to be specified correctly in makefiles and pkg-config.
>> 
>> 3. Anything with __attribute__((constructor)) runs *before* main, thus
>>   before PetscInitialize.  There would need to be a new mechanism to
>>   register a callback to be run at the end of PetscInitialize.
>
>    Are you saying we need something like PetscPlugInRegister(PetscErrorCode 
> (*)(void)) that can be called before PetscInitialize() by plugin libraries 
> that 
> registers the function that PetscInitialize() than calls? This is doable, 
> just needs to use malloc() directly and cannot use PETSc's FList constructs.

Yes, either with malloc or some fixed (fairly large) number of slots.
If using malloc, you'd want an __attribute__((destructor)) that runs
after main to free the list.  (You can't free it in PetscFinalize
because the user could call PetscInitialize again; you need to free it
to avoid Valgrind noise.)

Reply via email to