Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to add SPDX identifiers #13

Merged
merged 4 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# SPDX-FileCopyrightText: 2024 Binsparse Developers
#
# SPDX-License-Identifier: BSD-3-Clause

---
BasedOnStyle: LLVM
PointerAlignment: Left
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# SPDX-FileCopyrightText: 2024 Binsparse Developers
#
# SPDX-License-Identifier: BSD-3-Clause

name: "CI"

on:
Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-FileCopyrightText: 2024 Binsparse Developers
#
# SPDX-License-Identifier: BSD-3-Clause

scripts
venv
build
._*
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# SPDX-FileCopyrightText: 2024 Binsparse Developers
#
# SPDX-License-Identifier: BSD-3-Clause

repos:

- repo: https://github.com/pre-commit/mirrors-clang-format
Expand All @@ -12,3 +16,8 @@ repos:
- id: end-of-file-fixer
- id: mixed-line-ending
- id: check-added-large-files

- repo: https://github.com/fsfe/reuse-tool
rev: v2.1.0
hooks:
- id: reuse
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# SPDX-FileCopyrightText: 2024 Binsparse Developers
#
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required(VERSION 3.5)
project(binsparse-rc)

Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<!--
SPDX-FileCopyrightText: 2024 Binsparse Developers

SPDX-License-Identifier: BSD-3-Clause
-->

# Binsparse C Reference Implementation

This library is a reference implementation of the [binsparse Binary Sparse Format Specification](https://github.com/GraphBLAS/binsparse-specification) written using C.
Expand Down
5 changes: 5 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# SPDX-FileCopyrightText: 2024 Binsparse Developers
#
# SPDX-License-Identifier: BSD-3-Clause

function(add_example example_name)
add_executable(${example_name} ${example_name}.c)
target_link_libraries(${example_name} binsparse-rc)
Expand All @@ -10,6 +14,7 @@ add_example(simple_write)
add_example(mtx2bsp)
add_example(bsp2mtx)
add_example(check_equivalence)
add_example(check_equivalence_parallel)
add_example(bsp-ls)
add_example(benchmark_read)
add_example(benchmark_read_parallel)
Expand Down
6 changes: 6 additions & 0 deletions examples/benchmark_read.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* SPDX-FileCopyrightText: 2024 Binsparse Developers
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <binsparse/binsparse.h>
#include <stdlib.h>
#include <time.h>
Expand Down
16 changes: 12 additions & 4 deletions examples/benchmark_read_parallel.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* SPDX-FileCopyrightText: 2024 Binsparse Developers
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <binsparse/binsparse.h>
#include <stdlib.h>
#include <time.h>
Expand Down Expand Up @@ -61,8 +67,9 @@ int main(int argc, char** argv) {
char* file_name = argv[1];

printf("Opening %s\n", file_name);
fflush(stdout);

const int num_trials = 2;
const int num_trials = 10;

int num_threads = 6;

Expand All @@ -71,11 +78,10 @@ int main(int argc, char** argv) {
size_t nbytes = 0;

// To flush the filesystem cache before each trial, change to `true`.
bool cold_cache = true;
bool cold_cache = false;

// If running warm cache experiments, read once to warm cache.
if (!cold_cache && false) {
printf("Warm cache read...\n");
if (!cold_cache) {
bsp_matrix_t mat = bsp_read_matrix_parallel(file_name, NULL, num_threads);
bsp_destroy_matrix_t(mat);
}
Expand All @@ -84,6 +90,7 @@ int main(int argc, char** argv) {
if (cold_cache) {
flush_cache();
}
fflush(stdout);
double begin = gettime();
bsp_matrix_t mat = bsp_read_matrix_parallel(file_name, NULL, num_threads);
double end = gettime();
Expand All @@ -95,6 +102,7 @@ int main(int argc, char** argv) {
double gbytes = ((double) nbytes) / 1024 / 1024 / 1024;
double gbytes_s = gbytes / durations[i];
printf("FORPARSER: %s,%lf,%lf\n", file_name, durations[i], gbytes_s);
fflush(stdout);
}

printf("[");
Expand Down
6 changes: 6 additions & 0 deletions examples/benchmark_write.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* SPDX-FileCopyrightText: 2024 Binsparse Developers
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <binsparse/binsparse.h>
#include <stdlib.h>
#include <time.h>
Expand Down
6 changes: 6 additions & 0 deletions examples/bsp-ls.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* SPDX-FileCopyrightText: 2024 Binsparse Developers
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <binsparse/binsparse.h>

herr_t visit_group(hid_t loc_id, const char* name, const H5L_info_t* linfo,
Expand Down
6 changes: 6 additions & 0 deletions examples/bsp2mtx.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* SPDX-FileCopyrightText: 2024 Binsparse Developers
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <binsparse/binsparse.h>
#include <stdio.h>

Expand Down
6 changes: 6 additions & 0 deletions examples/check_equivalence.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* SPDX-FileCopyrightText: 2024 Binsparse Developers
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <binsparse/binsparse.h>

int check_array_equivalence(bsp_array_t array1, bsp_array_t array2) {
Expand Down
217 changes: 217 additions & 0 deletions examples/check_equivalence_parallel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
/*
* SPDX-FileCopyrightText: 2024 Binsparse Developers
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <binsparse/binsparse.h>

int check_array_equivalence(bsp_array_t array1, bsp_array_t array2) {
if (array1.size != array2.size) {
fprintf(stderr, "Array sizes do not match. %zu != %zu\n", array1.size,
array2.size);
return 1;
}

if (array1.size == 0) {
return 0;
}

bsp_matrix_market_type_t mm_type1 = BSP_MM_REAL;

if ((array1.type >= BSP_UINT8 && array1.type <= BSP_INT64) ||
array1.type == BSP_BINT8) {
mm_type1 = BSP_MM_INTEGER;
} else if (array1.type >= BSP_FLOAT32 && array1.type <= BSP_FLOAT64) {
mm_type1 = BSP_MM_REAL;
} else if (array1.type == BSP_COMPLEX_FLOAT32 ||
array1.type == BSP_COMPLEX_FLOAT64) {
mm_type1 = BSP_MM_COMPLEX;
} else {
fprintf(stderr, "Unhandled array type.\n");
return 2;
}

bsp_matrix_market_type_t mm_type2 = BSP_MM_REAL;

if ((array2.type >= BSP_UINT8 && array2.type <= BSP_INT64) ||
array2.type == BSP_BINT8) {
mm_type2 = BSP_MM_INTEGER;
} else if (array2.type >= BSP_FLOAT32 && array2.type <= BSP_FLOAT64) {
mm_type2 = BSP_MM_REAL;
} else if (array2.type == BSP_COMPLEX_FLOAT32 ||
array2.type == BSP_COMPLEX_FLOAT64) {
mm_type2 = BSP_MM_COMPLEX;
} else {
fprintf(stderr, "Unhandled array type.\n");
return 2;
}

if (mm_type1 != mm_type2) {
fprintf(stderr, "Array types do not match.\n");
return 3;
}

for (size_t i = 0; i < array1.size; i++) {
if (mm_type1 == BSP_MM_INTEGER) {
size_t value1, value2;
bsp_array_read(array1, i, value1);
bsp_array_read(array2, i, value2);

if (value1 != value2) {
fprintf(stderr, "Array values are not equal. (%zu != %zu)\n", value1,
value2);
return 4;
}
} else if (mm_type1 == BSP_MM_REAL) {
double value1, value2;
bsp_array_read(array1, i, value1);
bsp_array_read(array2, i, value2);

if (value1 != value2) {
fprintf(stderr, "Array values are not equal. (%.17lg != %.17lg)\n",
value1, value2);
return 4;
}
} else if (mm_type1 == BSP_MM_COMPLEX) {
double _Complex value1, value2;
bsp_array_read(array1, i, value1);
bsp_array_read(array2, i, value2);

if (value1 != value2) {
fprintf(stderr,
"Array values are not equal. (%.17lg + i%.17lg != %.17lg + "
"i%.17lg)\n",
__real__ value1, __imag__ value1, __real__ value2,
__imag__ value2);
return 4;
}
}
}

return 0;
}

int main(int argc, char** argv) {
if (argc < 3) {
printf(
"usage: ./check_equivalence [file1.{mtx/hdf5}] [file2.{mtx/hdf5}]\n");

printf(" Note: the second argument will be read in parallel if it is a "
"Binsparse file.\n");
return 1;
}

char* file1 = argv[1];
char* file2 = argv[2];

int num_threads = 6;

bsp_fdataset_info_t info1 = bsp_parse_fdataset_string(argv[1]);
bsp_fdataset_info_t info2 = bsp_parse_fdataset_string(argv[2]);

printf("Matrix 1: %s and %s\n", info1.fname,
(info1.dataset == NULL) ? "root" : info1.dataset);
printf("Matrix 2: %s and %s\n", info2.fname,
(info2.dataset == NULL) ? "root" : info2.dataset);

fflush(stdout);

bsp_matrix_t matrix1 = bsp_read_matrix(info1.fname, info1.dataset);
bsp_matrix_t matrix2 =
bsp_read_matrix_parallel(info2.fname, info2.dataset, num_threads);

bool perform_suitesparse_declamping = true;
if (perform_suitesparse_declamping &&
strcmp(bsp_get_file_extension(file1), ".mtx") == 0) {
bsp_matrix_declamp_values(matrix1);
}

if (perform_suitesparse_declamping &&
strcmp(bsp_get_file_extension(file2), ".mtx") == 0) {
bsp_matrix_declamp_values(matrix2);
}

// If matrices are not the same format, try to convert.
if (matrix1.format != matrix2.format) {
if (matrix1.format != BSP_COOR) {
bsp_matrix_t intermediate = bsp_convert_matrix(matrix1, BSP_COOR);
bsp_destroy_matrix_t(matrix1);
matrix1 = intermediate;
}

if (matrix2.format != BSP_COOR) {
bsp_matrix_t intermediate = bsp_convert_matrix(matrix2, BSP_COOR);
bsp_destroy_matrix_t(matrix2);
matrix2 = intermediate;
}
}

if (matrix1.format != matrix2.format) {
fprintf(stderr, "Formats do not match. (%s != %s)\n",
bsp_get_matrix_format_string(matrix1.format),
bsp_get_matrix_format_string(matrix2.format));
fprintf(stderr, "FAIL!\n");
return 1;
}

if (matrix1.structure != matrix2.structure) {
fprintf(stderr, "Structures do not match. (%s != %s)\n",
bsp_get_structure_string(matrix1.structure),
bsp_get_structure_string(matrix2.structure));
fprintf(stderr, "FAIL!\n");
return 2;
}

if (matrix1.nrows != matrix2.nrows || matrix1.ncols != matrix2.ncols) {
fprintf(stderr, "Dimensions do not match. (%zu, %zu) != (%zu, %zu)\n",
matrix1.nrows, matrix1.ncols, matrix2.nrows, matrix2.ncols);
fprintf(stderr, "FAIL!\n");
return 3;
}

if (matrix1.nnz != matrix2.nnz) {
fprintf(stderr, "Number of stored values does not match. %zu != %zu\n",
matrix1.nnz, matrix2.nnz);
fprintf(stderr, "FAIL!\n");
return 4;
}

if (matrix1.is_iso != matrix2.is_iso) {
fprintf(stderr, "ISO-ness does not match. %s != %s\n",
(matrix1.is_iso) ? "true" : "false",
(matrix2.is_iso) ? "true" : "false");
fprintf(stderr, "FAIL!\n");
return 5;
}

if (check_array_equivalence(matrix1.values, matrix2.values) != 0) {
fprintf(stderr, "Value arrays not equivalent.\n");
fprintf(stderr, "FAIL!\n");
return 6;
}

if (check_array_equivalence(matrix1.indices_0, matrix2.indices_0) != 0) {
fprintf(stderr, "Indices_0 arrays not equivalent.\n");
fprintf(stderr, "FAIL!\n");
return 7;
}

if (check_array_equivalence(matrix1.indices_1, matrix2.indices_1) != 0) {
fprintf(stderr, "Indices_1 arrays not equivalent.\n");
fprintf(stderr, "FAIL!\n");
return 8;
}

if (check_array_equivalence(matrix1.pointers_to_1, matrix2.pointers_to_1) !=
0) {
fprintf(stderr, "Pointers_to_1 arrays not equivalent.\n");
fprintf(stderr, "FAIL!\n");
return 9;
}

printf("The files are equivalent.\n");
printf("OK!\n");

return 0;
}
Loading
Loading