#Parallel computing problems, more threads = same or worse performance.

1 messages · Page 1 of 1 (latest)

kindred cape
#

I am trying to complete an assignment that requires us to do updates on a grid with various thread numbers and compare the speed.

Adding more threads makes no difference, and sometimes even results in worse time.

I do not use java a lot and so am unsure how to analyze my code to see if it is a task granularity problem or something else in the code.

wispy quiverBOT
#

<@&987246964494204979> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#
TJ-Bot
I am trying to complete an assignment that requires us to do updates on a grid with various thread numbers and compare the speed. Adding more threads makes no difference, and sometimes even results in worse time. I do not use java a lot and so am unsure

It is possible that adding more threads is actually causing contention and overhead, leading to worse performance. This could be due to factors such as resource constraints or inefficient synchronization mechanisms.

Useful links:

dire belfry
kindred cape
#

yup, one sec

#

This is the Main.java that controls the whole thing

public class Main {
    public static void main(String[] args) {

        long startTime = System.nanoTime();

        new GridUpdatev8().run(101, 100000, 3);  //array size, iterations, threads

        long endTime = System.nanoTime();
        long duration = endTime - startTime;
        System.out.println("Time taken: " + duration / 1_000_000_000.0 + " seconds");
    }
}

And the file is the GridUpdatev8.java class

wispy quiverBOT
wispy quiverBOT
deft leaf
#

Some candidates...

  • Time spent in contention on a resource (eg the processing of model updates or UI repaints, IO)
  • Costs of task division and task management
  • Latency between tasks
kindred cape
#

is there a way to tell where my bottleneck is with IntelliJ profiler or a similar tool?
I can't really understand what it's showing me

storm cave
wispy quiverBOT
#

@kindred cape

Your question has been closed due to inactivity.

If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.

Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.

When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.

Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.

With enough info, someone knows the answer for sure 👍

noble sun
noble sun
#

I ran your code through the profiler. Here's what I saw. 75-80% of the time is spent on managing Executor stuff, of that 5% is time waiting on latch.await, so it's mostly task submission that is the slow down. I increased the iteration to 1million to give it more to chew on and runtimes really don't change much. Originally it was 5 to 6 secs, regardless of number of threads used. After bumping iterations to 1million, 53-58sec.

Looking at the timeline feature of the profiler, which shows green/red coloring for time the thread is active/waiting, it shows that almost all the work is begin done in the first thread, and roughly logarithmically less for each additional thread. So number of threads doesn't matter because most of the work is being assigned to the first thread.

I remove the executor completely and just ran single threaded with 1million iterations and it was 22seconds, very different from 53-58seconds. So you can see that even using a single threaded executor is twice as slow (on my machine). So it's no wonder adding more threads just adds more overhead and zero performance gain.

Conclusion: the task you are running, the row calc, is too fine grained.

kindred cape
#

I'll try to find a better way to get things done now that you gave me an idea of how the profiler works.

noble sun
#

You also need to break up that one huge method into smaller methods otherwise the profiler has nothing to point to other than the one huge method.

#

If the size of the grid was increased you might see more thread use. Eventually you'll run up against L3 cache boundary though.

#

Also if you have a newer cpu, you might try Math.fma() for some of that row calc.
https://en.wikipedia.org/wiki/FMA_instruction_set

The FMA instruction set is an extension to the 128- and 256-bit Streaming SIMD Extensions instructions in the x86 microprocessor instruction set to perform fused multiply–add (FMA) operations. There are two variants:

FMA4 is supported in AMD processors starting with the Bulldozer architecture. FMA4 was performed in hardware before FMA3 was. S...

wispy quiverBOT
#

@kindred cape

Your question has been closed due to inactivity.

If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.

Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.

When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.

Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.

With enough info, someone knows the answer for sure 👍

stuck grail
#

Here is how to do it with a newer cpu