Will multi threading provide any performance boost?

前端 未结 19 822
说谎
说谎 2021-02-05 13:49

I am new to programming in general so please keep that in mind when you answer my question.

I have a program that takes a large 3D array (1 billion elements) and sums up

19条回答
  •  误落风尘
    2021-02-05 13:55

    I guess if you are just dealing with bits you might not have to page or use a swap file and in that case YES multi-threading will help.

    If you can't load everything into memory at once, you need to be more specific about your solution--it needs to be tailored to threading.

    For example: Suppose you load your array in smaller blocks (Size might not matter much). If you were to load in a 1000x1000x1000 cube, you could sum on that. The results could be stored temporarially in their own three plains, then added to your 3 "final result" planes, then the 1000^3 block could be thrown away never to be read again.

    If you do something like this, you won't run out of memory, you won't stress the swapfile and you won't have to worry about any thread synchronization except in a few very small, specific areas (if at all).

    The only problem then is to ensure your data is in such a format that you can access a single 1000^3 cube directly--without seeking the hard disk head all over the place.

    Edit: The comment was correct and I'm wrong--he totally makes sense.

    Since yesterday I realized that the entire problem could be solved as it was read in--each piece of data read in could immediately be summed into the results and discarded. When I think about it that way, you're right, not going to be much help unless the threading can read two streams at the same time without colliding.

提交回复
热议问题