Commit 28cc660b authored by Charles Bouillaguet's avatar Charles Bouillaguet
Browse files

bugfix : final buffer flush

parent f7e27846
......@@ -473,6 +473,17 @@ void output_setup()
buffer = alloc_array(buffer_capacity, sizeof(*buffer),"output buffer");
}
void flush_buffer()
{
if (buffer_stream != NULL) {
/* flush the old buffer to disk */
size_t check = fwrite(buffer, sizeof(*buffer), buffer_size, buffer_stream);
if (check != (size_t) buffer_size)
errx(1, "error when writing to disk");
}
buffer_size = 0;
}
/* write a row to the matrix file; return the row number */
int buffer_write_row(int row_size, int *row)
{
......@@ -485,15 +496,8 @@ int buffer_write_row(int row_size, int *row)
/* getting this out of the critical section requires the
use of an RCU-like mechanism */
if (buffer_size + row_size + 1 < buffer_capacity) {
if (buffer_stream != NULL) {
/* flush the old buffer to disk */
size_t check = fwrite(buffer + buffer_size, sizeof(*buffer), buffer_size, buffer_stream);
if (check != (size_t) buffer_size)
errx(1, "error when writing to disk");
}
buffer_size = 0;
}
if (buffer_size + row_size + 1 < buffer_capacity)
flush_buffer();
buffer[buffer_size] = row_size;
buffer_size += 1;
for (int k = 0; k < row_size; k++)
......@@ -530,6 +534,8 @@ void matrix_setup()
jlog = alloc_array(nrows, sizeof(*jlog), "jlog");
for (int j = 0; j < ncols; j++)
cw[j] = 0;
for (int i = 0; i < nrows; i++)
rw[i] = -1;
}
/* Store m_j * f_i in the sparse matrix, and update metadata.
......@@ -537,8 +543,7 @@ void matrix_setup()
Scratch should be a zero-filled array. This destroys row. */
void matrix_store_row(int i, int j, int *row, int size, bool *scratch)
{
int newrow[9000];
int newsize = 0;
for (int k = 0; k < size; k++) { // scan one, update scratch
int p = row[k];
int jj = bad_renumbering[p];
......@@ -547,6 +552,8 @@ void matrix_store_row(int i, int j, int *row, int size, bool *scratch)
continue; // skip good monomial
scratch[jj] ^= 1;
}
int newrow[9000];
int newsize = 0;
for (int k = 0; k < size; k++) { // scan again, read scratch
int jj = row[k];
if (jj >= 0 && scratch[jj]) {
......@@ -776,25 +783,35 @@ int main(int argc, char **argv)
log(0, "Sanity check\n");
/* check empty cols & rows */
int nempty_rows = 0;
for (int i = 0; i < nrows; i++)
if (rw[i] == 0)
u64 nnzr = 0;
for (int i = 0; i < nrows; i++) {
if (rw[i] <= 0)
nempty_rows++;
nnzr += rw[i];
}
if (nempty_rows == 0)
log(1, " - no empty rows (OK)\n");
else
errx(1, " - %d empty rows (KO)!\n", nempty_rows);
int nempty_cols = 0;
for (int j = 0; j < ncols; j++)
if (cw[j] == 0)
u64 nnzc = 0;
for (int j = 0; j < ncols; j++) {
if (cw[j] <= 0)
nempty_cols++;
nnzc += cw[j];
}
if (nempty_cols == 0)
log(1, " - no empty column (OK)\n");
else
errx(1, " - %d empty columnss (KO)!\n", nempty_cols);
assert(nnzr == nnzc);
assert(words_written == nnzr + nrows);
log(1, " - exact dimensions %d x %d (%ld nnz)\n", nrows, ncols, nnzr);
if (out_basename) {
log(0, "Finalization\n");
flush_buffer();
fclose(buffer_stream);
write_array(rw_filename, rw, nrows);
write_array(cw_filename, cw, ncols);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment