[petsc-users] Static Library based app for petsc

Matthew Knepley knepley at gmail.com
Wed Aug 25 06:03:21 CDT 2021


On Wed, Aug 25, 2021 at 1:00 AM Abhishek G.S. <gsabhishek1ags at gmail.com>
wrote:

> Thanks for the reply.
>
> On Wed, 25 Aug 2021 at 10:01, Jed Brown <jed at jedbrown.org> wrote:
>
>> PETSc does not "wrap" cout.
>>
>     What I meant here is that petsc has a custom output stream through
> PetscPrintf. I was wondering if that might have affected the stdout and
> hence the no print. The constructor in the libTest/include/test.h was just
> supposed to print a string when called in the benchmarks/Test1/main.cpp
>

PetscPrintf() just calls printf() underneath.


>
>> Creating a library first, with an executable front-end that most/all
>> initial users will use is generally good design. More users of the library
>> emerge as people try to do more advanced/custom things that are not
>> appropriate to do with the executable.
>>
>
> Ok... This makes sense.  (It would be great if you could point me towards
> some project whose structure I can borrow.)
> Why I did what I did was that if the petsc environment is encapsulated in
> the library, the rest of the code in the main.cpp would be outside. Since I
> was writing a code for a very small audience(mostly me) I thought it would
> be easier to debug if I was inside the petsc environment.
>

There are many codes that use PETSc in this way. For example,

  https://petsc.org/release/#related-toolkits-libraries-that-use-petsc

  Thanks,

    Matt


>
>
>
>>
>> "Abhishek G.S." <gsabhishek1ags at gmail.com> writes:
>>
>> > Hi,
>> > I am trying to develop a static-library-based app using petsc. The
>> > structure goes as,
>> > .
>> > ├── benchmarks
>> > │   └── Test1
>> > │       ├── main.cpp
>> > │       └── Makefile
>> > └── libTest
>> >     ├── build
>>
>> Are build products meant to go into this build/ directory, not under lib/
>> as you have it?
>>
>
> I routed the static library output to the libTest/lib folder in the
> libTest/CMakeLists.txt.
> The /benchmarks/Test1/Makefile includes this to the ld path
>
>
>>
>> >     ├── CMakeLists.txt
>> >     ├── include
>> >     │   ├── test.cpp
>>
>> cpp files would usually go under src/ or almost anywhere but in include/
>>
>
> noted.
>
>
>>
>> >     │   └── test.h
>> >     └── lib
>> >         └── libTest.a
>> >
>> > While this code compiles, I am unable to create a minimal working
>> example
>> > for the same. The aim is to just print "Hello World". Why is it that
>> > nothing prints?. Is it something to do with the PETSC wrapper for cout?
>> > Also, I would like to know whether it's a good idea to go ahead with
>> this
>> > kind of code structure.
>> >
>> > Thanks for the help.
>> >
>> > Code: https://github.com/gsabhishek/PetscStaticLibraryApp.git
>> >
>> > Thanks for the help
>>
>

-- 
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

https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20210825/b6bac3fa/attachment-0001.html>


More information about the petsc-users mailing list