Threads for calculations

I have a scrabble algorithm which looks basically like this.
These 4 routines must be sequentially executed.

for (Board.ALL_SQUARES) |square| self.gen(board, square, NORMAL, .Horizontal);
for (Board.ALL_SQUARES) |square| self.gen(board, square, NORMAL, .Vertical);
for (Board.ALL_SQUARES) |square| self.gen(board, square, CROSSWORDS, .Horizontal);
for (Board.ALL_SQUARES) |square| self.gen(board, square, CROSSWORDS, .Vertical);

Inside the generator are some square-info write things going on during gen.
The board is not touched and only read from.
And then I have the “global” movelist which is written to with each move found.

I never seriously worked with parallel threads but I would like to give it a try.

I was wondering: when processing horizontal or vertical the 15 rows the results are completely independent of eachother. Would that be a good candidate idea for using threads per row / column? Would it actually speed up things?

If so, are there some basic thread tips people have here?
The only thing I really know is that threads must not write in parallel to the same memory area.

Don’t forget that multi-threading adds an overhead. If you are doing very small tasks, you might actually get worse performance than just executing all in a single thread.

1 Like

true… I suspect the overhead is worse than the tasks.
There I sit, with my 20 cores doing nothing :slight_smile:

Do you actually have a performance problem?

1 Like

no, i’m a performance freak and like experiments

then go on, experiment :smiley:

post your finding after you’ve got conclusive results :stuck_out_tongue:

1 Like

I can experiment. I just asked the question to prevent me from taking 5 wrong experiment paths.

BTW, it’s not entirely true that you cannot write in parallel-ish. You can use mutex etc to make sure that each write happens when other writes do not happen.