New answers tagged

1

Your first snippet of code effectively assigns k1 to i and then checks i against the exit case. This is done every iteration and is why it is slower than the second snippet EDIT A possible workaround in pseudocode to have efficient iteration and still not relying on hard coding the value of i var i = k1; for i to 100000 //iterate next i


3

Instantiating and collecting small, short-lived, temporary objects, is perfectly fine. It is what modern garbage collectors are good at. Modern (generational) garbage collectors are built on a couple of assumptions: most objects die young, most objects are small, most objects don't escape, most objects are immutable, older objects don't contain references ...


-1

Garbage collection can become a performance issue in games, and might require special approaches. However, before you are sure that garbage collection of temporary Location instances is problematic, you would waste your time by trying to limit the amount of instances: “Premature optimization is the root of all evil.” To decide whether you should go down ...


0

Most likely your code has some undefined behavior (as others explained, you are much more likely to have bugs in your code than in the compiler, even if C++ compilers are so complex that they do have bugs; even the C++ specification has design bugs). And UB can be here even if the compiled executable happens to work (by bad luck). So you should read Lattner'...


1

An increasingly common situation is that compilers break code written for dialects of C that supported behaviors not mandated by the Standard, and allowed code targeting those dialects to be more efficient than strictly-conforming code could be. In such a case, it would be unfair to describe as "broken" code which would be 100% reliable on compilers that ...


0

Yes, it's certainly possible. Any computation that a CPU can do, a GPU can also do, and vice versa. But it's uncommon because: Engineering complexity While it is possible to run the same code on a CPU and GPU (e.g. CUDA), the processors have different abilities and performance characteristics. One is MIMD; the other, SIMD. What is fast on one is slow on ...


0

One real world example is the open source LuxRender rendering engine, which is capable of fully loading a CPU and GPU at the same time. In addition, it can load multiple GPUs at the same time and can also distribute across multiple computers. LuxRender uses OpenCL to facilitate this, although builds without OpenCL also exist. This is practical because ...


1

You might be interested in checking out the Servo browser engine being developed at Mozilla Research, and more specifically its Web Render (video). While shifting a task from CPU to GPU dynamically might be impractical, as mentioned in other answers (notably @Philip's), it can be practical to study the load of CPU/GPU on typical workloads in advance and ...


10

From a supercomputing viewpoint it is better not to think in CPU/GPU load in percentage but rather determine how many operations your problem at hand needs and then compare that to the peak performance of the system. If you get 100% CPU utilization it does not necessarily mean that you get all the performance out of the system. CPUs can often do multiple ...


0

With a focus on games (since you mentioned it specifically in your post), there are some ways you can balance the load. One example is "skinning", i.e. animating a model. For each frame to be rendered, you have to generate the transformation matrices for each frame of animation and apply it to the vertices of the model to transform it into the pose it needs ...



Top 50 recent answers are included