DrTimothyAldenDavis / SuiteSparse

The official SuiteSparse library: a suite of sparse matrix algorithms authored or co-authored by Tim Davis, Texas A&M University.
https://people.engr.tamu.edu/davis/suitesparse.html
Other
1.19k stars 265 forks source link

Use same objects for linking to shared and static libraries. #876

Closed mmuetzel closed 2 days ago

mmuetzel commented 1 month ago

Avoid building all objects twice (for the shared and the static library), effectively reducing the build time approximately by a factor of two.

Something similar could probably be done for most of the SuiteSparse libraries (including GraphBLAS). So, build time could probably be reduced by a lot (when building shared and static libraries).

DrTimothyAldenDavis commented 3 weeks ago

Looks great! That came out very clean.

My organization requires a minor revision to my Contributor Agreement, for all new contributions. Can you sign the new one I just posted? It's here in the dev branch:

https://github.com/DrTimothyAldenDavis/SuiteSparse/blob/dev/Contributor_License/SuiteSparse%20Individual%20Contributor%20License%20Agreement%20(20241011).pdf

mmuetzel commented 1 week ago

I applied the same idea to some other SuiteSparse libraries and pushed here.

It looks like that doesn't work in general though. 😓 Maybe, position-independent code in static vs. shared libraries? On some platforms only? 🤔

mmuetzel commented 1 week ago

Explicitly compiling with -fPIC seems to fix it. (At least, it is able to link libsuitesparseconfig.so on Linux with that change.)

Would that be an ok fix? IIUC, static libraries are built without -fPIC by default...

Edit: I wonder why that wasn't necessary for libamd.so...

DrTimothyAldenDavis commented 1 week ago

Explicitly compiling with -fPIC seems to fix it. (At least, it is able to link libsuitesparseconfig.so on Linux with that change.)

Would that be an ok fix? IIUC, static libraries are built without -fPIC by default...

Edit: I wonder why that wasn't necessary for libamd.so...

Oh ... that could be a show-stopper. I think I shouldn't create static libraries with -fPIC. That could really be backward breaking change to the many users of the SuiteSparse static libraries. There's no telling what could break. It seems very dangerous to go down this path.

Adding -fPIC to static libraries can make them slower, for example. I think there's a reason that some people want to use static libraries and avoid -fPIC. The reasons might be more than just performance.