Split build_dense_matrix to two methods: build_dense_matrix_sequentially and build_dense_matrix_in_parallel