diff --git a/cpp_prototype/CMakeLists.txt b/cpp_prototype/CMakeLists.txt new file mode 100644 index 000000000..40a3a6b0c --- /dev/null +++ b/cpp_prototype/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.10) + +message(STATUS "CMake version ${CMAKE_VERSION}") + +set(LANGUAGES C CXX) +set(BML_BUILD_FORTRAN_INTERFACE TRUE CACHE BOOL + "Build the Fortran API (requires a Fortran compiler)") +if(BML_BUILD_FORTRAN_INTERFACE) + list(APPEND LANGUAGES Fortran) +endif() + +set(BML_BUILD_PYTHON_INTERFACE TRUE CACHE BOOL + "Build the Python API (requires Python dev package)") + +project(bml ${LANGUAGES}) + +add_subdirectory(src) + +enable_testing() +add_subdirectory(tests) diff --git a/cpp_prototype/src/CMakeLists.txt b/cpp_prototype/src/CMakeLists.txt new file mode 100644 index 000000000..61cd4f200 --- /dev/null +++ b/cpp_prototype/src/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(bml + bml_allocate.cc) diff --git a/cpp_prototype/src/bml.h b/cpp_prototype/src/bml.h new file mode 100644 index 000000000..cb32cfbf4 --- /dev/null +++ b/cpp_prototype/src/bml.h @@ -0,0 +1,7 @@ +#ifndef __BML_H +#define __BML_H + +#include "bml_types.h" +#include "bml_allocate.h" + +#endif diff --git a/cpp_prototype/src/bml_allocate.cc b/cpp_prototype/src/bml_allocate.cc new file mode 100644 index 000000000..0a4235f43 --- /dev/null +++ b/cpp_prototype/src/bml_allocate.cc @@ -0,0 +1,30 @@ +#include "bml_types.h" + +#include + +/** Allocate the identity matrix. + * + * Note that the matrix \f$ A \f$ will be newly allocated. The + * function does not check whether the matrix is already allocated. + * + * \ingroup allocate_group_C + * + * \param matrix_type The matrix type. + * \param matrix_precision The precision of the matrix. + * \param N The matrix size. + * \param M The number of non-zeroes per row. + * \param distrib_mode The distribution mode. + * \return The matrix. + */ +BMLMatrix * +bml_identity_matrix( + bml_matrix_type_t matrix_type, + bml_matrix_precision_t matrix_precision, + int N, + int M, + bml_distribution_mode_t distrib_mode) +{ + BMLMatrix * A = new BMLMatrix(); + + return A; +} diff --git a/cpp_prototype/src/bml_allocate.h b/cpp_prototype/src/bml_allocate.h new file mode 100644 index 000000000..a2aad7277 --- /dev/null +++ b/cpp_prototype/src/bml_allocate.h @@ -0,0 +1,14 @@ +#ifndef __BML_ALLOCATE_H +#define __BML_ALLOCATE_H + +#include "bml_types.h" + +BMLMatrix * +bml_identity_matrix( + bml_matrix_type_t matrix_type, + bml_matrix_precision_t matrix_precision, + int N, + int M, + bml_distribution_mode_t distrib_mode); + +#endif diff --git a/cpp_prototype/src/bml_types.cc b/cpp_prototype/src/bml_types.cc new file mode 100644 index 000000000..d06add7c9 --- /dev/null +++ b/cpp_prototype/src/bml_types.cc @@ -0,0 +1 @@ +#include "bml_types.h" diff --git a/cpp_prototype/src/bml_types.h b/cpp_prototype/src/bml_types.h new file mode 100644 index 000000000..df2cfa01a --- /dev/null +++ b/cpp_prototype/src/bml_types.h @@ -0,0 +1,98 @@ +#ifndef __BML_TYPES_H +#define __BML_TYPES_H + +/** The BML matrix type. */ +class BMLMatrix +{ + /** The number of rows/columns. */ + int N; +}; + +/** The supported matrix types. */ +typedef enum +{ + /** The matrix is not initialized. */ + type_uninitialized, + /** Dense matrix. */ + dense, + /** ELLPACK matrix. */ + ellpack, + /** BLOCK ELLPACK matrix. */ + ellblock, + /** ELLSORT matrix. */ + ellsort, + /** CSR matrix. */ + csr, + /** distributed matrix. */ + distributed2d +} bml_matrix_type_t; + +/** The supported real precisions. */ +typedef enum +{ + /** The matrix is not initialized. */ + precision_uninitialized, + /** Matrix data is stored in single precision (float). */ + single_real, + /** Matrix data is stored in double precision (double). */ + double_real, + /** Matrix data is stored in single-complex precision (float). */ + single_complex, + /** Matrix data is stored in double-complex precision (double). */ + double_complex +} bml_matrix_precision_t; + +/** The supported dense matrix elements orderings. */ +typedef enum +{ + /** row-major order. */ + dense_row_major, + /** column-major order. */ + dense_column_major +} bml_dense_order_t; + +/** The supported distribution modes. */ +typedef enum +{ + /** Each rank works on the full matrix. */ + sequential, + /** Each rank works on its part of the matrix. */ + distributed, + /** Each rank works on its set of graph partitions. */ + graph_distributed +} bml_distribution_mode_t; + +/** Decomposition for working in parallel. */ +struct bml_domain_t +{ + /** number of processors */ + int totalProcs; + /** total number of rows */ + int totalRows; + /** total number of columns */ + int totalCols; + + /** global minimum row number */ + int globalRowMin; + /** global maximum row number */ + int globalRowMax; + /** global total rows */ + int globalRowExtent; + + /** maximum extent for most processors */ + int maxLocalExtent; + /** minimum extent for last processors */ + int minLocalExtent; + /** minimum row per rank */ + int *localRowMin; + /** maximum row per rank */ + int *localRowMax; + /** extent of rows per rank, localRowMax - localRowMin */ + int *localRowExtent; + /** local number of elements per rank */ + int *localElements; + /** local displacements per rank for 2D */ + int *localDispl; +}; + +#endif diff --git a/cpp_prototype/tests/CMakeLists.txt b/cpp_prototype/tests/CMakeLists.txt new file mode 100644 index 000000000..78c4111b5 --- /dev/null +++ b/cpp_prototype/tests/CMakeLists.txt @@ -0,0 +1,6 @@ +include_directories(${PROJECT_SOURCE_DIR}/src) +add_executable(bml-test + bml-test.cc) +target_link_libraries(bml-test bml) +add_test(NAME allocate + COMMAND bml-test) diff --git a/cpp_prototype/tests/bml-test.cc b/cpp_prototype/tests/bml-test.cc new file mode 100644 index 000000000..352c78665 --- /dev/null +++ b/cpp_prototype/tests/bml-test.cc @@ -0,0 +1,8 @@ +#include +#include +#include + +int main() { + printf("starting tests\n"); + BMLMatrix * A = bml_identity_matrix(dense, double_real, 10, 10, sequential); +}