Use multi-threading using the rayon crate
Last updated
Last updated
is a popular crate to easily write multi-threaded code in Rust.
It is possible to use rayon to write multi-threaded TFHE-rs code. However due to internal details of rayon
and TFHE-rs
, there is some special setup that needs to be done.
The high level api requires to call set_server_key
on each thread where computations needs to be done. So a first attempt at using rayon with TFHE-rs
might look like this:
However, due to rayon's work stealing mechanism and TFHE-rs's internals, this may create `BorrowMutError'.
The correct way is to call rayon::broadcast
If your application needs to operate on data from different clients concurrently, and that you want each client to use multiple threads, you will need to create different rayon thread pools
This can be useful if you have some rust #[test]