I have a huge binary matrix, like 100000 x 100000.
Reading this article http://www.cs.up.ac.za/cs/vpieterse/pub/PieterseEtAl_SAICSIT2010.pdf, I seemed to understand that the best tradeoff to memorize and work with a binary matrix is using boost::dynamic_bitsets.
Since in "Table 2: Relative time performance of the programs that implemented the data structures" : std::vector<bool> is in last position, while boost::dynamic_bitset is in first position.
And in "Table 3: Relative memory usage of the programs that implemented the data structures": std::vector<bool> is in first position, but boost::dynamic_bitset is in second position.
Besides, in the paper, at page 7th, there is the following statement:
"Despite the impressive memory performance of std::vector, its dismal time performance renders it unusable in large-scale applications."
And in the conclusions:
"We have shown that boost::dynamic_bitset is considerably more efficient than most of the other implementations in terms of execution speed, while the implementation using std::vector<char> outperformed the other implementations in terms of memory efficiency."
Now in my case, my target machine is a XEON PHI.
My target application is Game Of Life.
I have rappresented the binary matrix as a binary array of ROWS x COLS cells.
I have tried the code with 3 different configurations, bulding them with -the icpc compiler with -O3 optimization flag:
- Array of booleans
- Array of booleans + vectorization, i.e. changing the code using the Array Notation as described here
boost::dynamic_bitsets. In this case, I could not change the code using the Array Notation since, when I try, I get the following error:
error: base of array section must be pointer or array type
same error when using std::vector<bool>.
Looking to the performance of just one iteration of the game main loop for a matrix of 100000 x 100000 size, I have found that: solution 2 works almost six times faster than solution 1, but unexpectedly solution 1 works twice faster than solution 3.
In conclusion, I have the following questions to make:
- What is, in general, the most efficient data structure to store/work with an HUGE MATRIX ?
- Can I do better than "answer 1" knowing that my target machine is a XEON PHI ?
- Is it possible to apply vectorization to vector<bool> or boost::dynamic_bitsets ?
Thanks for the answer about the specific target application: Game Of Life.
But what about working with a huge binary matrix in other context ?