These are chat archives for rust-lang/rust

18th
Mar 2019
ozgurakkurt
@ozgurakkurt
Mar 18 10:41

hi, I wrote a matrix multiplication code and I want to parallelize it with rayon but I can't get it to work. The code is here: https://github.com/ozgurakkurt/mlxd/blob/master/src/lib.rs. I want to make the outer loop of sgemm_o3 parallel like this:

pub fn sgemm_o3(a: &[f32], b: &[f32], c: &mut [f32], n: usize) {
    (0..n/BLOCK_SIZE).into_par_iter().for_each(|sj| {
        let sj = sj * BLOCK_SIZE;
        for si in (0..n).step_by(BLOCK_SIZE) {
            for sk in (0..n).step_by(BLOCK_SIZE) {
                sgemm_o3_do_block(a, b, c, n, si, sj, sk);
            }
        }
    });
}

I know this is bad for rust since I am mutating c from multiple threads. How can I make this work?

Denis Lisov
@tanriol
Mar 18 11:36
Which part of c does this access?
Looks like you need to iterate over mutable chunks of c, not indices.
And no, transmute is not an answer.
verilog15
@verilog15
Mar 18 17:08
@tanriol Thanks. can you explain a bit more? which transitivity we can see here?
John
@onFireForGod_gitlab
Mar 18 21:27
is it possible to create a trait based on what type of fields a struct has?
I have structures that differ in one field, how can a trait be implemented to indicate the common fields?
Brian Knapp
@knappador
Mar 18 21:45
@onFireForGod_gitlab traits don't contain information about fields. They're more like interfaces. You can compose structures.
Sam Johnson
@sam0x17
Mar 18 23:55
for the life of me I can't get rust to let me use my crate (bitfort) in its tests.rs file:
#[cfg(test)]
mod tests {
    use bitfort::stream::*;

    #[test]
    fn it_works() {
        assert_eq!(2 + 2, 4);
        let mut limiter = Limiter::new(Print); // these symbols should import from bitfort::stream::*
    }
}
// lib.rs
pub mod stream;
pub mod tests;