Comments (8)
I think JVM respect tasksets:
$ cat test.sc
println(Runtime.getRuntime().availableProcessors())
$ scala-cli run test.sc
Compiling project (Scala 3.4.1, JVM (21))
Compiled project (Scala 3.4.1, JVM (21))
12
$ taskset -c 0-0 scala-cli run test.sc
1
$ taskset -c 0-0 scala-cli run --native test.sc
** compiler output snipped **
12
from scala-native.
@amsen20 That particular method is suppose to indicate the number of cores or hyperthreads and should match what the JVM reports. OMP looks like you need to set the number of cores OMP will use. Glancing at the docs (not an OpenMP user) shows that you can also set an env var to do what you are doing with taskset
above. There could be a problem if our method doesn't match what the JVM report. I guess that would be a good job for scala-cli
. Thanks for bringing this to our attention.
Ref: https://curc.readthedocs.io/en/latest/programming/OpenMP-C.html
from scala-native.
For reference this is how nproc
(the GNU coreutils command to get the number of available processors) implement this query with linux/bsd APIs.
Note that if you look at num_processors
(the main function) at the end of the file, nproc
also follows OpenMP environment variables, but we don't have to (and the JVM doesn't either).
from scala-native.
aI took some time looking at this Issue. The "taskset" JVM/SN comparison helped a lot.
-
I can not read the nproc source because that is almost certainly GPL licensed.
-
Just to make sure I am on the correct page, by "availableProcessors" we are talking about
"number of logical processes (threads)" not "number of hardware cores". The JavaRuntime.getavaibleProcessors()
description is particularly silent there.
It appears to me that this Issue divides into three parts:
-
Windows -- I have no expertise there, so any PR would need to use the current code until someone
with windows expertise & testing system could fix it. -
BSD systems -- These are the easier path to code. The core/logical_processor distinction is keenest here.
The time consuming part here is figuring out the "compile only if used" condition compilation of the
.c file. I think the pieces are in place to do that, just not fixed in my brain or fingers yet.-
I can test macOS easily. In a pinch I can test FreeBSD.
-
I have no access to NetBSD. I hate leaving untested
code active, so I propose to fail the compilation on NetBSD. It ought to work and be easy for a NetBSD
champion to remove the guard
-
-
Linux -- The simple case where number of configured (logical) CPUs is less than 1025 should be
comparatively simple. The difficulty comes from the <= 1024 restriction. Conditional compilation only on
use is a, I believe surmountable, thorn in the path here.-
Getting the number of hardware cores would be more difficult: reading & parsing files, which might not exist, depending
on how the was configured. -
I propose to fallback to current code if the
sched_getaffinity()
code returns -1 & errno EINVAL (invalid argument)
This restriction would lead to a more timely PR. -
amsen20: would this be useful to you until a PR handling > 1024 logical processors could be created & tested?
-
-
Does anybody have access to a recent Linux system with (much) greater than 1024 logical processors?
I can write code intended to handle such but I have learned through private & public shame & hard experience
not to release untested code.I have not checked, but I think coming up with such a large number of processors might not be feasable
on Amazon EC cloud.
Thunderstorms & power failures coming, gotta go.
from scala-native.
Unless someone has evidence to the contrary, I think OpenMP environment should be handled
by the application, not javalib. Consensus?
from scala-native.
In my use case I am not even near using 1024 threads, so resolving it for <=1024 hyper threads until a PR comes would be great for me.
from scala-native.
amsen20,
Does PR #3969 give you what you want/need? It is Linux only, with nProcessors <= 1024.
Please advise. I can make additional changes if this baselevel does not solve this Issue (for Linux).
Thank you, once again, for finding & reporting this defect.
Lee
from scala-native.
Yeah, it works for my use case well.
Thanks.
from scala-native.
Related Issues (20)
- `java.lang.Process.waitFor` unable to handle broken pipe HOT 7
- several covariant javalib BaseStream declarations should be invariant.
- PR #3946 should be reverted; JVM `Process#waitFor` can validly return InterruptedException HOT 2
- ThreadLocal.Values#getAfterMiss can get into an infinite loop
- javalib `Process#waitFor(timeout)` macOS & unix-like os calls should be in a try/finally block HOT 1
- How to map a large struct? HOT 19
- Compiler produces a confusing unrelated error in presence of Zone HOT 1
- how to use @struct? HOT 1
- Potential doubling linking in Scala Native 0.5
- javalib ProcessTest needs distinguished assertions
- Scala Native / Fails to compile & produce object files for the larger header (.h) files HOT 4
- Properly sized and aligned union representation
- IEEE 754 Negative zeros get no respect. HOT 3
- Defects in Scala Native javalib IEEE 754 handling of negative zero in constructor HOT 2
- javalib Math#min & Math#max do not consistently handle IEEE754 negative zero on CI LLVM versions.
- ReleaseFast mangles java.Double IEEE 754 negative zeros
- Scala Native execution can hang in Scala 2.13 HOT 1
- javalib List class could benefit from work HOT 4
- Proposed work plan for some javalib post Java 8 improvements HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scala-native.