Skip to content

Commit

Permalink
Add example for parallel sort
Browse files Browse the repository at this point in the history
It is now clearer how to use this library. The example(s) are built by default.
  • Loading branch information
Connor-GH committed Oct 11, 2024
1 parent 4bb45f8 commit f7dcd7c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
readme = "README.md"
repository = "https://github.com/STEllAR-GROUP/hpx-rs"
description = """
Bindings to hpx for interoperating with stellar-group hpx library for
Bindings to hpx for interoperating with stellar-group hpx library for
concurrency and parallelism.
"""
categories = ["api-bindings"]
Expand All @@ -17,4 +17,4 @@ publish = false
hpx-sys = { path = "hpx-sys", version = "0.1.0" }

[workspace]
members = []
members = [ "hpx-examples"]
7 changes: 7 additions & 0 deletions hpx-examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "hpx-examples"
version = "0.1.0"
edition = "2021"

[dependencies]
hpx-sys = { path = "../hpx-sys", version = "0.1.0" }
32 changes: 32 additions & 0 deletions hpx-examples/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#![feature(vec_into_raw_parts)]
#![feature(random)]
use core::array::from_fn;
use std::{process, random, ffi::c_char, env};

use hpx_sys as hpx;

fn hpx_main(argc: i32, argv: *mut *mut c_char) -> i32 {

let numbers: &[i32; 16384] = &from_fn(|_| random::random::<i32>());
let list: &mut Vec<i32> = &mut Vec::<i32>::from(numbers);
println!("{:#?}", list);
// Sort the array in parallel.
hpx::hpx_sort_comp(list, |a, b| a < b);
println!("{:#?}", list);
hpx::finalize();
return 0;
}
fn main() {
let args = env::args();
let (argc, argv) = hpx::create_c_args(&args
.collect::<Vec<String>>()
.iter()
.map(|s| s.as_str())
.collect::<Vec<&str>>()
);
unsafe {
process::exit(hpx::init(hpx_main, argc, argv
.into_raw_parts()
.0));
}
}
1 change: 1 addition & 0 deletions hpx-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub mod ffi {
fn hpx_partial_sort_comp(src: &mut Vec<i32>, last: usize, comp: fn(i32, i32) -> bool);
}
}
pub use self::ffi::*;

// ================================================================================================
// Wrapper for the above Bindings.
Expand Down

0 comments on commit f7dcd7c

Please sign in to comment.