Skip to content

Instantly share code, notes, and snippets.

@dagss
Created February 22, 2012 19:58
Show Gist options
  • Save dagss/1886892 to your computer and use it in GitHub Desktop.
Save dagss/1886892 to your computer and use it in GitHub Desktop.
/* DO NOT EDIT THIS FILE, IT IS GENERATED */
/*!*/
/*!*/
/*!*/
/*!*/
/*!*/
/*!*/
/*!*/ #include <stdio.h>
/*!*/ #include <string.h>
/*!*/
/*!*/ #include "elemental_wrapper.h"
/*!*/ #include "elemental.hpp"
/*!*/
/*!*/ using namespace elem;
/*!*/
/*!*/ static Orientation as_orientation(int x) {
/*!*/ switch (x) {
/*!*/ case ELEM_NORMAL:
/*!*/ return NORMAL;
/*!*/ case ELEM_TRANSPOSE:
/*!*/ return TRANSPOSE;
/*!*/ case ELEM_ADJOINT:
/*!*/ return ADJOINT;
/*!*/ default:
/*!*/ throw std::logic_error("invalid orientation code");
/*!*/ }
/*!*/ }
/*!*/
/*!*/
/*!*/ #define MAX_ERR_LEN 1024
/*!*/ static char _errmsg[MAX_ERR_LEN];
/*!*/
/*!*/ static void set_error(const char *msg) {
/*!*/ strncpy(_errmsg, msg, MAX_ERR_LEN);
/*!*/ _errmsg[MAX_ERR_LEN - 1] = '\0'; // in case of truncation
/*!*/ }
/*!*/
/*!*/
/*!*/
/*!*/
/*!*/
/*!*/ char *elem_errmsg() {
/*!*/ return _errmsg;
/*!*/ }
/*!*/
/*!*/ int elem_initialize(int* argc, char **argv) {
/*!*/ try {
/*!*/ Initialize(*argc, argv);
/*!*/ return 0;
/*!*/ } catch (std::exception &e) {
/*!*/ set_error(e.what());
/*!*/ return NULL;
/*!*/ } catch (...) {
/*!*/ set_error("non-std exception");
/*!*/ return NULL;
/*!*/ }
/*!*/ }
/*!*/
/*!*/ void elem_finalize() {
/*!*/ try {
/*!*/ Finalize();
/*!*/ } catch (...) {
/*!*/ return;
/*!*/ }
/*!*/ }
/*!*/
/*!*/
/*!*/
/*!*/ elem_matrix *elem_create_matrix(int dtype, int col_dist, int row_dist,
/*!*/ int height, int width, int col_alignment,
/*!*/ int row_alignment, void *buffer,
/*!*/ int lda, elem_grid *grid_handle) {
/*!*/ const Grid& grid = *(const Grid*)grid_handle;
/*!*/
/*!*/ try {
/*!*/ if (0) {}
/*!*/
/*!*/ else if ((dtype) == ELEM_DOUBLE_COMPLEX) {
/*!*/
/*!*/
/*!*/
/*!*/ if (0) {}
/*!*/ else if ((col_dist) == ELEM_MC &&
/*!*/ (row_dist) == ELEM_MR) {
/*!*/ DistMatrix<Complex<double> , MC, MR, int> *matrix = new DistMatrix<Complex<double> , MC, MR, int> (
/*!*/ height, width, col_alignment, row_alignment,
/*!*/ (Complex<double> *)buffer, lda, grid);
/*!*/ elem_matrix *wrapper = new elem_matrix();
/*!*/ wrapper->dtype = dtype;
/*!*/ wrapper->col_dist = col_dist;
/*!*/ wrapper->row_dist = row_dist;
/*!*/ wrapper->cpp_obj = matrix;
/*!*/ return wrapper;
/*!*/
/*!*/ }
/*!*/ else if ((col_dist) == ELEM_MC &&
/*!*/ (row_dist) == ELEM_STAR) {
/*!*/ DistMatrix<Complex<double> , MC, STAR, int> *matrix = new DistMatrix<Complex<double> , MC, STAR, int> (
/*!*/ height, width, col_alignment,
/*!*/ (Complex<double> *)buffer, lda, grid);
/*!*/ elem_matrix *wrapper = new elem_matrix();
/*!*/ wrapper->dtype = dtype;
/*!*/ wrapper->col_dist = col_dist;
/*!*/ wrapper->row_dist = row_dist;
/*!*/ wrapper->cpp_obj = matrix;
/*!*/ return wrapper;
/*!*/
/*!*/ }
/*!*/ else {
/*!*/ throw std::logic_error("invalid colDist/rowDist combination");
/*!*/ }
/*!*/
/*!*/
/*!*/ }
/*!*/ else if ((dtype) == ELEM_DOUBLE_REAL) {
/*!*/
/*!*/
/*!*/
/*!*/ if (0) {}
/*!*/ else if ((col_dist) == ELEM_MC &&
/*!*/ (row_dist) == ELEM_MR) {
/*!*/ DistMatrix<double, MC, MR, int> *matrix = new DistMatrix<double, MC, MR, int> (
/*!*/ height, width, col_alignment, row_alignment,
/*!*/ (double*)buffer, lda, grid);
/*!*/ elem_matrix *wrapper = new elem_matrix();
/*!*/ wrapper->dtype = dtype;
/*!*/ wrapper->col_dist = col_dist;
/*!*/ wrapper->row_dist = row_dist;
/*!*/ wrapper->cpp_obj = matrix;
/*!*/ return wrapper;
/*!*/
/*!*/ }
/*!*/ else if ((col_dist) == ELEM_MC &&
/*!*/ (row_dist) == ELEM_STAR) {
/*!*/ DistMatrix<double, MC, STAR, int> *matrix = new DistMatrix<double, MC, STAR, int> (
/*!*/ height, width, col_alignment,
/*!*/ (double*)buffer, lda, grid);
/*!*/ elem_matrix *wrapper = new elem_matrix();
/*!*/ wrapper->dtype = dtype;
/*!*/ wrapper->col_dist = col_dist;
/*!*/ wrapper->row_dist = row_dist;
/*!*/ wrapper->cpp_obj = matrix;
/*!*/ return wrapper;
/*!*/
/*!*/ }
/*!*/ else {
/*!*/ throw std::logic_error("invalid colDist/rowDist combination");
/*!*/ }
/*!*/
/*!*/
/*!*/ }
/*!*/ else if ((dtype) == ELEM_SINGLE_COMPLEX) {
/*!*/
/*!*/
/*!*/
/*!*/ if (0) {}
/*!*/ else if ((col_dist) == ELEM_MC &&
/*!*/ (row_dist) == ELEM_MR) {
/*!*/ DistMatrix<Complex<float> , MC, MR, int> *matrix = new DistMatrix<Complex<float> , MC, MR, int> (
/*!*/ height, width, col_alignment, row_alignment,
/*!*/ (Complex<float> *)buffer, lda, grid);
/*!*/ elem_matrix *wrapper = new elem_matrix();
/*!*/ wrapper->dtype = dtype;
/*!*/ wrapper->col_dist = col_dist;
/*!*/ wrapper->row_dist = row_dist;
/*!*/ wrapper->cpp_obj = matrix;
/*!*/ return wrapper;
/*!*/
/*!*/ }
/*!*/ else if ((col_dist) == ELEM_MC &&
/*!*/ (row_dist) == ELEM_STAR) {
/*!*/ DistMatrix<Complex<float> , MC, STAR, int> *matrix = new DistMatrix<Complex<float> , MC, STAR, int> (
/*!*/ height, width, col_alignment,
/*!*/ (Complex<float> *)buffer, lda, grid);
/*!*/ elem_matrix *wrapper = new elem_matrix();
/*!*/ wrapper->dtype = dtype;
/*!*/ wrapper->col_dist = col_dist;
/*!*/ wrapper->row_dist = row_dist;
/*!*/ wrapper->cpp_obj = matrix;
/*!*/ return wrapper;
/*!*/
/*!*/ }
/*!*/ else {
/*!*/ throw std::logic_error("invalid colDist/rowDist combination");
/*!*/ }
/*!*/
/*!*/
/*!*/ }
/*!*/ else if ((dtype) == ELEM_SINGLE_REAL) {
/*!*/
/*!*/
/*!*/
/*!*/ if (0) {}
/*!*/ else if ((col_dist) == ELEM_MC &&
/*!*/ (row_dist) == ELEM_MR) {
/*!*/ DistMatrix<float, MC, MR, int> *matrix = new DistMatrix<float, MC, MR, int> (
/*!*/ height, width, col_alignment, row_alignment,
/*!*/ (float*)buffer, lda, grid);
/*!*/ elem_matrix *wrapper = new elem_matrix();
/*!*/ wrapper->dtype = dtype;
/*!*/ wrapper->col_dist = col_dist;
/*!*/ wrapper->row_dist = row_dist;
/*!*/ wrapper->cpp_obj = matrix;
/*!*/ return wrapper;
/*!*/
/*!*/ }
/*!*/ else if ((col_dist) == ELEM_MC &&
/*!*/ (row_dist) == ELEM_STAR) {
/*!*/ DistMatrix<float, MC, STAR, int> *matrix = new DistMatrix<float, MC, STAR, int> (
/*!*/ height, width, col_alignment,
/*!*/ (float*)buffer, lda, grid);
/*!*/ elem_matrix *wrapper = new elem_matrix();
/*!*/ wrapper->dtype = dtype;
/*!*/ wrapper->col_dist = col_dist;
/*!*/ wrapper->row_dist = row_dist;
/*!*/ wrapper->cpp_obj = matrix;
/*!*/ return wrapper;
/*!*/
/*!*/ }
/*!*/ else {
/*!*/ throw std::logic_error("invalid colDist/rowDist combination");
/*!*/ }
/*!*/
/*!*/
/*!*/ }
/*!*/ else {
/*!*/ throw std::logic_error("invalid dtype");
/*!*/ }
/*!*/ } catch (std::exception& e) {
/*!*/ set_error(e.what());
/*!*/ return NULL;
/*!*/ } catch (...) {
/*!*/ set_error("non-std exception");
/*!*/ return NULL;
/*!*/ }
/*!*/
/*!*/ }
/*!*/
/*!*/ void elem_destroy_matrix(elem_matrix *matrix) {
/*!*/ int _dtype = matrix->dtype;
/*!*/ try {
/*!*/ if (0) {}
/*!*/
/*!*/ else if ((_dtype) == ELEM_DOUBLE_COMPLEX) {
/*!*/
/*!*/
/*!*/
/*!*/ delete (AbstractDistMatrix<Complex<double> , int> *)matrix->cpp_obj;
/*!*/ delete matrix;
/*!*/
/*!*/
/*!*/
/*!*/ }
/*!*/ else if ((_dtype) == ELEM_DOUBLE_REAL) {
/*!*/
/*!*/
/*!*/
/*!*/ delete (AbstractDistMatrix<double, int> *)matrix->cpp_obj;
/*!*/ delete matrix;
/*!*/
/*!*/
/*!*/
/*!*/ }
/*!*/ else if ((_dtype) == ELEM_SINGLE_COMPLEX) {
/*!*/
/*!*/
/*!*/
/*!*/ delete (AbstractDistMatrix<Complex<float> , int> *)matrix->cpp_obj;
/*!*/ delete matrix;
/*!*/
/*!*/
/*!*/
/*!*/ }
/*!*/ else if ((_dtype) == ELEM_SINGLE_REAL) {
/*!*/
/*!*/
/*!*/
/*!*/ delete (AbstractDistMatrix<float, int> *)matrix->cpp_obj;
/*!*/ delete matrix;
/*!*/
/*!*/
/*!*/
/*!*/ }
/*!*/ else {
/*!*/ throw std::logic_error("invalid dtype");
/*!*/ }
/*!*/ } catch (std::exception& e) {
/*!*/ } catch (...) {
/*!*/ }
/*!*/
/*!*/
/*!*/ }
/*!*/
/*!*/ int elem_gemm(int orientation_of_a,
/*!*/ int orientation_of_b,
/*!*/ elem_complex alpha,
/*!*/ elem_matrix *A,
/*!*/ elem_matrix *B,
/*!*/ elem_complex beta,
/*!*/ elem_matrix *C) {
/*!*/ if (((B)->dtype != (A)->dtype) ||
/*!*/ ((B)->col_dist != (A)->col_dist) ||
/*!*/ ((B)->row_dist != (A)->row_dist)) {
/*!*/ set_error("dtype/col_dist/row_dist does not match up");
/*!*/ return ELEM_ERROR_LOGIC;
/*!*/ }
/*!*/ if (((C)->dtype != (A)->dtype) ||
/*!*/ ((C)->col_dist != (A)->col_dist) ||
/*!*/ ((C)->row_dist != (A)->row_dist)) {
/*!*/ set_error("dtype/col_dist/row_dist does not match up");
/*!*/ return ELEM_ERROR_LOGIC;
/*!*/ }
/*!*/ int _dtype = A->dtype;
/*!*/ int _col_dist = A->col_dist;
/*!*/ int _row_dist = A->row_dist;
/*!*/ try {
/*!*/ if (0) {}
/*!*/
/*!*/ else if ((_dtype) == ELEM_DOUBLE_COMPLEX) {
/*!*/
/*!*/
/*!*/
/*!*/ if (0) {}
/*!*/ else if ((_col_dist) == ELEM_MC &&
/*!*/ (_row_dist) == ELEM_MR) {
/*!*/ Gemm(as_orientation(orientation_of_a),
/*!*/ as_orientation(orientation_of_b),
/*!*/ (Complex<double> ((alpha).real, (alpha).imag)),
/*!*/ (*((DistMatrix<Complex<double> , MC, MR, int> *)(A)->cpp_obj)),
/*!*/ (*((DistMatrix<Complex<double> , MC, MR, int> *)(B)->cpp_obj)),
/*!*/ (Complex<double> ((beta).real, (beta).imag)),
/*!*/ (*((DistMatrix<Complex<double> , MC, MR, int> *)(C)->cpp_obj)));
/*!*/
/*!*/ }
/*!*/ else {
/*!*/ throw std::logic_error("invalid colDist/rowDist combination");
/*!*/ }
/*!*/
/*!*/
/*!*/ }
/*!*/ else if ((_dtype) == ELEM_DOUBLE_REAL) {
/*!*/
/*!*/
/*!*/
/*!*/ if (0) {}
/*!*/ else if ((_col_dist) == ELEM_MC &&
/*!*/ (_row_dist) == ELEM_MR) {
/*!*/ Gemm(as_orientation(orientation_of_a),
/*!*/ as_orientation(orientation_of_b),
/*!*/ ((double)(alpha).real),
/*!*/ (*((DistMatrix<double, MC, MR, int> *)(A)->cpp_obj)),
/*!*/ (*((DistMatrix<double, MC, MR, int> *)(B)->cpp_obj)),
/*!*/ ((double)(beta).real),
/*!*/ (*((DistMatrix<double, MC, MR, int> *)(C)->cpp_obj)));
/*!*/
/*!*/ }
/*!*/ else {
/*!*/ throw std::logic_error("invalid colDist/rowDist combination");
/*!*/ }
/*!*/
/*!*/
/*!*/ }
/*!*/ else if ((_dtype) == ELEM_SINGLE_COMPLEX) {
/*!*/
/*!*/
/*!*/
/*!*/ if (0) {}
/*!*/ else if ((_col_dist) == ELEM_MC &&
/*!*/ (_row_dist) == ELEM_MR) {
/*!*/ Gemm(as_orientation(orientation_of_a),
/*!*/ as_orientation(orientation_of_b),
/*!*/ (Complex<float> ((alpha).real, (alpha).imag)),
/*!*/ (*((DistMatrix<Complex<float> , MC, MR, int> *)(A)->cpp_obj)),
/*!*/ (*((DistMatrix<Complex<float> , MC, MR, int> *)(B)->cpp_obj)),
/*!*/ (Complex<float> ((beta).real, (beta).imag)),
/*!*/ (*((DistMatrix<Complex<float> , MC, MR, int> *)(C)->cpp_obj)));
/*!*/
/*!*/ }
/*!*/ else {
/*!*/ throw std::logic_error("invalid colDist/rowDist combination");
/*!*/ }
/*!*/
/*!*/
/*!*/ }
/*!*/ else if ((_dtype) == ELEM_SINGLE_REAL) {
/*!*/
/*!*/
/*!*/
/*!*/ if (0) {}
/*!*/ else if ((_col_dist) == ELEM_MC &&
/*!*/ (_row_dist) == ELEM_MR) {
/*!*/ Gemm(as_orientation(orientation_of_a),
/*!*/ as_orientation(orientation_of_b),
/*!*/ ((float)(alpha).real),
/*!*/ (*((DistMatrix<float, MC, MR, int> *)(A)->cpp_obj)),
/*!*/ (*((DistMatrix<float, MC, MR, int> *)(B)->cpp_obj)),
/*!*/ ((float)(beta).real),
/*!*/ (*((DistMatrix<float, MC, MR, int> *)(C)->cpp_obj)));
/*!*/
/*!*/ }
/*!*/ else {
/*!*/ throw std::logic_error("invalid colDist/rowDist combination");
/*!*/ }
/*!*/
/*!*/
/*!*/ }
/*!*/ else {
/*!*/ throw std::logic_error("invalid dtype");
/*!*/ }
/*!*/ return 0;
/*!*/ } catch (std::exception& e) {
/*!*/ set_error(e.what());
/*!*/ return ELEM_ERROR_LOGIC;
/*!*/ } catch (...) {
/*!*/ set_error("non-std exception");
/*!*/ return ELEM_ERROR_LOGIC;
/*!*/ }
/*!*/
/*!*/
/*!*/ }
/*!*/
/*!*/ int elem_print(elem_matrix *matrix) {
/*!*/ int _dtype = matrix->dtype;
/*!*/ try {
/*!*/ if (0) {}
/*!*/
/*!*/ else if ((_dtype) == ELEM_DOUBLE_COMPLEX) {
/*!*/
/*!*/
/*!*/
/*!*/ (*((AbstractDistMatrix<Complex<double> , int> *)(matrix)->cpp_obj)).Print();
/*!*/
/*!*/
/*!*/
/*!*/ }
/*!*/ else if ((_dtype) == ELEM_DOUBLE_REAL) {
/*!*/
/*!*/
/*!*/
/*!*/ (*((AbstractDistMatrix<double, int> *)(matrix)->cpp_obj)).Print();
/*!*/
/*!*/
/*!*/
/*!*/ }
/*!*/ else if ((_dtype) == ELEM_SINGLE_COMPLEX) {
/*!*/
/*!*/
/*!*/
/*!*/ (*((AbstractDistMatrix<Complex<float> , int> *)(matrix)->cpp_obj)).Print();
/*!*/
/*!*/
/*!*/
/*!*/ }
/*!*/ else if ((_dtype) == ELEM_SINGLE_REAL) {
/*!*/
/*!*/
/*!*/
/*!*/ (*((AbstractDistMatrix<float, int> *)(matrix)->cpp_obj)).Print();
/*!*/
/*!*/
/*!*/
/*!*/ }
/*!*/ else {
/*!*/ throw std::logic_error("invalid dtype");
/*!*/ }
/*!*/ return 0;
/*!*/ } catch (std::exception& e) {
/*!*/ set_error(e.what());
/*!*/ return ELEM_ERROR_LOGIC;
/*!*/ } catch (...) {
/*!*/ set_error("non-std exception");
/*!*/ return ELEM_ERROR_LOGIC;
/*!*/ }
/*!*/
/*!*/
/*!*/ }
/*!*/
/*!*/ int elem_set_to_identity(elem_matrix *matrix) {
/*!*/ int _dtype = matrix->dtype;
/*!*/ try {
/*!*/ if (0) {}
/*!*/
/*!*/ else if ((_dtype) == ELEM_DOUBLE_COMPLEX) {
/*!*/
/*!*/
/*!*/
/*!*/ (*((AbstractDistMatrix<Complex<double> , int> *)(matrix)->cpp_obj)).SetToIdentity();
/*!*/
/*!*/
/*!*/
/*!*/ }
/*!*/ else if ((_dtype) == ELEM_DOUBLE_REAL) {
/*!*/
/*!*/
/*!*/
/*!*/ (*((AbstractDistMatrix<double, int> *)(matrix)->cpp_obj)).SetToIdentity();
/*!*/
/*!*/
/*!*/
/*!*/ }
/*!*/ else if ((_dtype) == ELEM_SINGLE_COMPLEX) {
/*!*/
/*!*/
/*!*/
/*!*/ (*((AbstractDistMatrix<Complex<float> , int> *)(matrix)->cpp_obj)).SetToIdentity();
/*!*/
/*!*/
/*!*/
/*!*/ }
/*!*/ else if ((_dtype) == ELEM_SINGLE_REAL) {
/*!*/
/*!*/
/*!*/
/*!*/ (*((AbstractDistMatrix<float, int> *)(matrix)->cpp_obj)).SetToIdentity();
/*!*/
/*!*/
/*!*/
/*!*/ }
/*!*/ else {
/*!*/ throw std::logic_error("invalid dtype");
/*!*/ }
/*!*/ return 0;
/*!*/ } catch (std::exception& e) {
/*!*/ set_error(e.what());
/*!*/ return ELEM_ERROR_LOGIC;
/*!*/ } catch (...) {
/*!*/ set_error("non-std exception");
/*!*/ return ELEM_ERROR_LOGIC;
/*!*/ }
/*!*/
/*!*/
/*!*/ }
/*!*/
/*!*/
/*!*/
/*!*/
/*!*/ elem_grid *elem_create_grid(MPI_Comm comm, int height, int width) {
/*!*/ try {
/*!*/ return (elem_grid*)(new Grid(comm, height, width));
/*!*/ } catch (std::exception &e) {
/*!*/ set_error(e.what());
/*!*/ return NULL;
/*!*/ } catch (...) {
/*!*/ set_error("non-std exception");
/*!*/ return NULL;
/*!*/ }
/*!*/ }
/*!*/
/*!*/ void elem_destroy_grid(elem_grid *grid) {
/*!*/ delete (Grid*)grid;
/*!*/ }
/*!*/
/*!*/ int elem_local_length(int n, int index, int alignment, int modulus) {
/*!*/ return LocalLength(n, index, alignment, modulus);
/*!*/ }
/*!*/ int elem_grid_mcrank(elem_grid *grid) {
/*!*/ return ((Grid*)grid)->MCRank();
/*!*/ }
/*!*/ int elem_grid_mrrank(elem_grid *grid) {
/*!*/ return ((Grid*)grid)->MRRank();
/*!*/ }
/*!*/ int elem_grid_height(elem_grid *grid) {
/*!*/ return ((Grid*)grid)->Height();
/*!*/ }
/*!*/ int elem_grid_width(elem_grid *grid) {
/*!*/ return ((Grid*)grid)->Width();
/*!*/ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment