Sam Schlinkert is a user on octodon.social. You can follow them or interact with them if you have an account anywhere in the fediverse. If you don't, you can sign up here.
Sam Schlinkert @schlink

I wrote a script that is, as expected, taking some time and CPU resources. However I see that it's only using one of my 8 cores(?) (see screenshot).

If I were to use threads in Rust could I use more than one CPU? octodon.social/media/YxBLdEj5e

· Web · 0 · 0

@schlink if the script’s work can be split across threads then yes, that should be the case, and it should run several times faster.

from what I’ve seen, the easiest way to do this is to use #Rayon, github.com/rayon-rs/rayon

So I used to check the EFF large diceword list for problematic compound words. It only took 11+ hours!

(SPOILER ALERT: I didn't find any!)

github.com/sts10/half-entropy-

@schlink doc.rust-lang.org/book/second-

I do believe you have to make the program parallel by yourself, though there are probably wrappers over these lower-level constructs.

@mathuin right, yeah, for sure I knew I'd need to implement something code-wise. Just wanted to make sure Rust threads would be able to use more than one of my cores.

and re-wrapper, @carey sent me link to : github.com/rayon-rs/rayon

Haven't tried it yet though, but it looks really lightweight

@schlink @carey Yeah that's what I was actually looking for. I believe it's pretty efficient, I mean that's one of rust's main goals, zero-cost abstractions.

@mathuin @carey

right -- my issue is that I wrote my big loop as a `for` loop (like `for word in word_list { do things }`). Can I just do

word_list.par_iter( |word|
do things
)

my code: github.com/sts10/half-entropy-

@carey @mathuin

ah, sorry. bet it's

words.par_iter().for_each(|word|
println!("Word is {}", word)
);

@schlink @carey My initial thought is that there would be no issue, but I've yet to do enough rust to be sure.

@mathuin @schlink That’s what I understand should work, too. Maybe even

for word in words.par_iter() {
println!(...)
}

noting that println! uses a mutex lock, so that specific example will probably get slower.