Skip to content

Commit

Permalink
Add prototype using C++
Browse files Browse the repository at this point in the history
This prototype includes the dense and CSR matrix types and the identity matrix
allocation API.

Language bindings are not included.

Issue: #570

Signed-off-by: Nicolas Bock <[email protected]>
  • Loading branch information
nicolasbock committed Feb 7, 2022
1 parent 3529cda commit d6c7853
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cpp_prototype/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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}) # don't move this line as it changes PROJECT_SOURCE_DIR

add_subdirectory(src)
add_subdirectory(tests)
2 changes: 2 additions & 0 deletions cpp_prototype/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_library(bml
bml_allocate.cc)
4 changes: 4 additions & 0 deletions cpp_prototype/src/bml.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#ifndef __BML_H
#define __BML_H

#endif
28 changes: 28 additions & 0 deletions cpp_prototype/src/bml_allocate.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "bml_types.h"

#include <stdlib.h>

/** 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)
{
return NULL;
}
1 change: 1 addition & 0 deletions cpp_prototype/src/bml_types.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "bml_types.h"
79 changes: 79 additions & 0 deletions cpp_prototype/src/bml_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#ifndef __BML_TYPES_H
#define __BML_TYPES_H

/** The BML matrix type. */
class BMLMatrix
{
/** The number of rows/columns. */
int N;
};

/** 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
5 changes: 5 additions & 0 deletions cpp_prototype/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include_directories(${CMAKE_SOURCE_DIR}/src)
add_executable(bml-test
bml-test.cc)

add_test(NAME allocate COMMAND bml-test)
8 changes: 8 additions & 0 deletions cpp_prototype/tests/bml-test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <bml.h>
#include <stdlib.h>
#include <stdio.h>

int main() {
printf("starting tests\n");
return 1;
}

0 comments on commit d6c7853

Please sign in to comment.