amgcl icon indicating copy to clipboard operation
amgcl copied to clipboard

Serialize/deserialize preconditioner?

Open DABH opened this issue 4 years ago • 3 comments

I have a program that I run multiple times. Each time the program runs it uses the same linear system A and solves Ax=b (using AMGCL) with a different right-hand side. Therefore, every time my program runs it's recomputing the preconditioner for the system with AMGCL. Is there any way to serialize the preconditioner to disk (some binary file etc.), and then deserialize the preconditioner (or solver object?) on a subsequent run? It would save a significant amount of time if this were possible since constructing the preconditioner is slow. Thanks for any tips or ideas you might have!

DABH avatar Jan 13 '20 04:01 DABH

Serialization is not currently possible in amgcl. I am not even sure it is possible to implement it in a generic way: amgcl moves preconditioner data (matrices and vectors) to the backend selected by the user as soon as it does not need the internal structures. Some of the backends (such as CUDA/CUSPARSE) store the data in opaque, non-serializable, formats.

I guess it could be implemented for the builtin backend, using something like boost::serialization, but I am not sure how much time/effort that would take.

What kind of preconditioner do you use? Does setup really take much longer than the solution? I would make sure that compiler optimizations are enabled during compilation, as C++ can be really slow in debug mode.

ddemidov avatar Jan 13 '20 06:01 ddemidov

I guess the way to do it would be to serialize whatever internal structures are built right before sending them to the backend.

I'm using the MPI+AMG preconditioner with Chebyshev, and VexCL backend (using CUDA/GPUs). Compiler optimizations (-O3 etc.) are definitely enabled. For a very large (few billion degrees of freedom) and distributed system, with a sufficiently strong preconditioner, constructing the preconditioner can take 3-5min while solving the system is like 2min. So I think there would be a legitimate benefit to being able to quickly load a pre-computed preconditioner rather than rebuilding the same preconditioner every time. But not sure how common my use case is :)

DABH avatar Jan 14 '20 19:01 DABH

I guess the way to do it would be to serialize whatever internal structures are built right before sending them to the backend.

Yes, that is a viable idea.

Each time the program runs it uses the same linear system A and solves Ax=b (using AMGCL) with a different right-hand side

By the way, is it possible to setup the preconditioner once and then use it with different right-hand-sides within a single run of the program?

ddemidov avatar Jan 14 '20 19:01 ddemidov