Can't you do impl Send for DGGRS or similar in your code base to add these if necessary?
I have to check if that is possible without touching the dggal_cffi.rs script that you created.
What were you trying to run in parallel?
Please consider this minimal example:
extern crate ecrt;
use ecrt::Application;
extern crate dggal;
use dggal::{DGGAL, DGGRS, GeoPoint};
use std;
use std::env;
use std::time::Instant;
fn main() {
let args: Vec<String> = env::args().collect();
let my_app = Application::new(&args);
let dggal = DGGAL::new(&my_app);
let dggrs: DGGRS = DGGRS::new(&dggal, "IVEA3H").expect("Unknown DGGRS");
let pnt: GeoPoint = GeoPoint {
lat: 52.3,
lon: 12.3,
};
let zone = dggrs.getZoneFromWGS84Centroid(8, &pnt);
println!("The Zone ID for the given point is: \n{:?}\n\n", zone);
let sub_zones = dggrs.getSubZones(zone, 5);
let t0 = Instant::now();
let ga: Vec<_> = sub_zones
.iter()
.map(|zone: &u64| {
let z: u64 = *zone;
println!("{:?}", z);
dggrs.getZoneWGS84Vertices(z)
})
.collect();
println!("iter getZoneWGS84Verticies() took {:.2?}", t0.elapsed());
let t1 = Instant::now();
use rayon::prelude::*;
let ga: Vec<_> = sub_zones
.par_iter() // WARN: par_iter does not work because the underlying ecere/dggal C FFI is not thread safe.
.map(|zone: &u64| {
let z: u64 = *zone;
println!("{:?}", z);
dggrs.getZoneWGS84Vertices(z)
})
.collect();
println!("par_iter getZoneWGS84Verticies() took {:.2?}", t1.elapsed());
}
I am looping over the subzone IDs with iter() and par_iter() to e.g. generate the geometry. You can comment out the lower part with par_iter() to see that the regular iter() works. Thanks!
Originally posted by @MichaelJendryke in GeoPlegma/GeoPlegma#25 (comment)
I have to check if that is possible without touching the
dggal_cffi.rsscript that you created.Please consider this minimal example:
I am looping over the subzone IDs with
iter()andpar_iter()to e.g. generate the geometry. You can comment out the lower part withpar_iter()to see that the regulariter()works. Thanks!Originally posted by @MichaelJendryke in GeoPlegma/GeoPlegma#25 (comment)