简体   繁体   English

Java raytracer增加CPU使用率

[英]Java raytracer increase CPU usage

I tried to implement a raytracer in Java and everything works fine. 我试图用Java实现raytracer,并且一切正常。 Once, I was rendering a scene and I checked the CPU-Usage of my program. 一次,我渲染了一个场景,然后检查了程序的CPU使用情况。 Every virtual core was being used but the overall CPU-Usage was around 22-23% 每个虚拟内核都在使用,但总体CPU使用率约为22-23%

I know that when I was rendering something with Cinema4D every virtual core was being used 100%. 我知道当我用Cinema4D渲染东西时,每个虚拟内核都被100%使用。

How could I archive this? 我该如何存档? Will it make my raytracer run 4 times faster? 它将使我的raytracer运行速度提高4倍吗? (23% -> 100%) (23%-> 100%)

You should definitely be able to get to 100% CPU usage, and all else being equal, doing so should result in faster rendering speed. 您绝对应该能够达到100%的CPU使用率,并且在其他所有条件相同的情况下,这样做应该可以加快渲染速度。 That you're apparently not at 100% indicates to me that you're either not creating enough threads, or your threads are blocking on something. 您显然没有达到100%的比例向我表明,您创建的线程不足,或者您的线程阻塞了某些东西。

I've found the sweet spot is one rendering thread per virtual core. 我发现最有效的方法是每个虚拟核心有一个渲染线程。 You can use the API to detect the number of cores available at runtime, and spawn that many rendering threads. 您可以使用API​​来检测运行时可用的内核数量,并产生许多渲染线程。 For an example of this, see my java ray tracer . 有关此示例,请参阅我的java ray tracer

Every virtual core was being used but the overall CPU-Usage was around 22-23% 每个虚拟内核都在使用,但总体CPU使用率约为22-23%

I'm not sure what you mean by this, but you may want to dig into it using a performance profiler to better understand how your threads are using CPU. 我不确定这是什么意思,但您可能想使用性能分析器对其进行深入研究,以更好地了解线程如何使用CPU。 Ideally you want each of your threads to be working all the time. 理想情况下,您希望每个线程一直在工作。 I use VisualVM to visualize process threads. 我使用VisualVM可视化进程线程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM