D
D
DVirt2017-12-19 20:17:18
big data
DVirt, 2017-12-19 20:17:18

How to quickly get the sum of numbers in a large array?

Hello.
There is an array of length 12 454 100 992, each cell of the array contains a positive or negative number.
How can you get the sum of all numbers as quickly as possible, while NOT parallelizing into threads and calculations are performed on a 3700 MHz processor (a video card is not provided)?
I'll add my question.
It's probably easier to write in assembler with bit shifts than to do it in a high-level language like 2+2.
Here is a snag, where will the calculations be faster?
PS Interested in the time spent on the action of transferring the value + commands to the register. Those. whether the execution time of this command written in C or assembler will differ

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Roman Kitaev, 2017-12-19
@deliro

Your question boils down to a degenerate question: "Is it possible to guess the data on the disk without knowing the nature of this data, but knowing only the length."
Answer: you can't.
I really highly doubt that the assembler will be able to unwind your hard faster than C. Or do you think that hardware arithmetic will be slower than hard?

V
Vladimir Olohtonov, 2017-12-19
@sgjurano

Go from beginning to end, summing up the elements.
One way or another, you will have to read them from the disk at least once, and if so, then you can simply sum them up, it’s better to read them in blocks to minimize io.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question