Tigran Bayburtsyan
Tigran Bayburtsyan

Reputation: 263

How do I use all processor cores during execution?

I'm writing a threaded program in Rust.

Go has an environment variable GOMAXPROCS which is used by the Go compiler to use the maximum amount of processor cores during execution. I found the RTRACEMAXPROCS parameter here after many searches, but I can't find any documentation for this.

Is the RTRACEMAXPROCS parameter the same as GOMAXPROCS for Rust?

Is it good practice to use over 800K threads in single process or should I use multiple processes?

Upvotes: 4

Views: 2508

Answers (2)

user395760
user395760

Reputation:

Rust doesn't have green threads any more. Every "task" you spawn maps to exactly one real OS thread (which is why the task terminology has fallen out of favor completely). An equivalent of GOMAXPROCS doesn't make sense.

As for the second part of your question: 800K threads is ludicrous. It might work, but don't expect it to work nearly as well as Go's or Erlang's green threads. In particular, each thread reserves a couple of megabytes of address space and at least 4 KiB physical memory, plus whatever resources the OS needs for the thread (not a lot, I've been told). The "spawn concurrent workers for every little thing" paradigm is not very well supported.

Upvotes: 4

Leo Correa
Leo Correa

Reputation: 19789

From looking at the code of your source RTRACEMAXPROCS is not actually part of Rust but of the program being used in the example.

https://github.com/Byron/rust-tracer/blob/5f6008c6b3c97471d965ed3113be0b7d6800b289/src/rust/main.rs#L46-L53

The author is simply using that environment variable to create a thread pool of a specified size.

So short answer is No, RTRACEMAXPROCS and GOMAXPROCS are not the same thing.

Upvotes: 0

Related Questions