Skip to content

Commit

Permalink
Merge pull request #77 from nicolasbock/issue_75
Browse files Browse the repository at this point in the history
Issue 75
  • Loading branch information
nicolasbock authored Jul 25, 2017
2 parents 2cfaf5a + b93a366 commit b124eda
Show file tree
Hide file tree
Showing 26 changed files with 184 additions and 197 deletions.
6 changes: 3 additions & 3 deletions src/C-interface/bml_scale.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
bml_matrix_t *
bml_scale_new(
const double scale_factor,
const void *scale_factor,
const bml_matrix_t * A)
{
bml_matrix_t *B = NULL;
Expand Down Expand Up @@ -50,7 +50,7 @@ bml_scale_new(
*/
void
bml_scale(
const double scale_factor,
const void *scale_factor,
const bml_matrix_t * A,
bml_matrix_t * B)
{
Expand Down Expand Up @@ -80,7 +80,7 @@ bml_scale(
*/
void
bml_scale_inplace(
const double scale_factor,
const void *scale_factor,
bml_matrix_t * A)
{
switch (bml_get_type(A))
Expand Down
8 changes: 3 additions & 5 deletions src/C-interface/bml_scale.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@

#include "bml_types.h"

// Scales A and returns a new B
bml_matrix_t *bml_scale_new(
const double scale_factor,
const void *scale_factor,
const bml_matrix_t * A);

// Scales A and returns in existing B
void bml_scale(
const double scale_factor,
const void *scale_factor,
const bml_matrix_t * A,
bml_matrix_t * B);

void bml_scale_inplace(
const double scale_factor,
const void *scale_factor,
bml_matrix_t * A);

#endif
4 changes: 3 additions & 1 deletion src/C-interface/dense/bml_add_dense_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ void TYPED_FUNC(
const double alpha,
const double beta)
{
bml_scale_inplace_dense(alpha, A);
REAL_T _alpha = (REAL_T) alpha;

bml_scale_inplace_dense(&_alpha, A);
bml_add_identity_dense(A, beta);
}
2 changes: 0 additions & 2 deletions src/C-interface/dense/bml_adjungate_triangle_dense_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ void TYPED_FUNC(
bml_matrix_dense_t * A,
char *triangle)
{

int N = A->N;
char mychar;

REAL_T *A_matrix = A->matrix;

Expand Down
2 changes: 0 additions & 2 deletions src/C-interface/dense/bml_copy_dense_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,11 @@ void TYPED_FUNC(
}

// Reorder elements in each row - just change index
REAL_T tmp;
#pragma omp parallel for
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
tmp = A_matrix[ROWMAJOR(i, j, N, N)];
A_matrix[ROWMAJOR(i, j, N, N)] =
B_matrix[ROWMAJOR(i, perm[j], N, N)];
}
Expand Down
4 changes: 0 additions & 4 deletions src/C-interface/dense/bml_multiply_dense_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@ void TYPED_FUNC(
REAL_T alpha_ = (REAL_T) alpha;
REAL_T beta_ = (REAL_T) beta;

int myRank = bml_getMyRank();

C_BLAS(GEMM) ("N", "N", &A->N, &A->N, &A->N, &alpha_, B->matrix,
&A->N, A->matrix, &A->N, &beta_, C->matrix, &A->N);

// mkl_thread_free_buffers();
}

/** Matrix multiply.
Expand Down
6 changes: 3 additions & 3 deletions src/C-interface/dense/bml_scale_dense.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
bml_matrix_dense_t *
bml_scale_dense_new(
const double scale_factor,
const void *scale_factor,
const bml_matrix_dense_t * A)
{
bml_matrix_dense_t *B = NULL;
Expand Down Expand Up @@ -57,7 +57,7 @@ bml_scale_dense_new(
*/
void
bml_scale_dense(
const double scale_factor,
const void *scale_factor,
const bml_matrix_dense_t * A,
bml_matrix_dense_t * B)
{
Expand Down Expand Up @@ -85,7 +85,7 @@ bml_scale_dense(

void
bml_scale_inplace_dense(
const double scale_factor,
const void *scale_factor,
bml_matrix_dense_t * A)
{
switch (A->matrix_precision)
Expand Down
32 changes: 17 additions & 15 deletions src/C-interface/dense/bml_scale_dense.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,71 @@

#include "bml_types_dense.h"

#include <complex.h>

bml_matrix_dense_t *bml_scale_dense_new(
const double scale_factor,
const void *scale_factor,
const bml_matrix_dense_t * A);

bml_matrix_dense_t *bml_scale_dense_new_single_real(
const double scale_factor,
const float *scale_factor,
const bml_matrix_dense_t * A);

bml_matrix_dense_t *bml_scale_dense_new_double_real(
const double scale_factor,
const double *scale_factor,
const bml_matrix_dense_t * A);

bml_matrix_dense_t *bml_scale_dense_new_single_complex(
const double scale_factor,
const float complex * scale_factor,
const bml_matrix_dense_t * A);

bml_matrix_dense_t *bml_scale_dense_new_double_complex(
const double scale_factor,
const double complex * scale_factor,
const bml_matrix_dense_t * A);

void bml_scale_dense(
const double scale_factor,
const void *scale_factor,
const bml_matrix_dense_t * A,
bml_matrix_dense_t * B);

void bml_scale_dense_single_real(
const double scale_factor,
const float *scale_factor,
const bml_matrix_dense_t * A,
bml_matrix_dense_t * B);

void bml_scale_dense_double_real(
const double scale_factor,
const double *scale_factor,
const bml_matrix_dense_t * A,
bml_matrix_dense_t * B);

void bml_scale_dense_single_complex(
const double scale_factor,
const float complex * scale_factor,
const bml_matrix_dense_t * A,
bml_matrix_dense_t * B);

void bml_scale_dense_double_complex(
const double scale_factor,
const double complex * scale_factor,
const bml_matrix_dense_t * A,
bml_matrix_dense_t * B);

void bml_scale_inplace_dense(
const double scale_factor,
const void *scale_factor,
bml_matrix_dense_t * A);

void bml_scale_inplace_dense_single_real(
const double scale_factor,
const float *scale_factor,
bml_matrix_dense_t * A);

void bml_scale_inplace_dense_double_real(
const double scale_factor,
const double *scale_factor,
bml_matrix_dense_t * A);

void bml_scale_inplace_dense_single_complex(
const double scale_factor,
const float complex * scale_factor,
bml_matrix_dense_t * A);

void bml_scale_inplace_dense_double_complex(
const double scale_factor,
const double complex * scale_factor,
bml_matrix_dense_t * A);

#endif
23 changes: 6 additions & 17 deletions src/C-interface/dense/bml_scale_dense_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,17 @@
*/
bml_matrix_dense_t *TYPED_FUNC(
bml_scale_dense_new) (
const double scale_factor,
const REAL_T * scale_factor,
const bml_matrix_dense_t * A)
{
REAL_T sfactor = (REAL_T) scale_factor;

bml_matrix_dense_t *B = TYPED_FUNC(bml_copy_dense_new) (A);
REAL_T *B_matrix = B->matrix;
int myRank = bml_getMyRank();
//int nElems = B->N * B->N;
int nElems = B->domain->localRowExtent[myRank] * B->N;
int startIndex = B->domain->localDispl[myRank];
int inc = 1;

C_BLAS(SCAL) (&nElems, &sfactor, &(B_matrix[startIndex]), &inc);
//C_BLAS(SCAL) (&nElems, &sfactor, B->matrix, &inc);
C_BLAS(SCAL) (&nElems, scale_factor, &(B_matrix[startIndex]), &inc);

return B;
}
Expand All @@ -54,40 +50,33 @@ bml_matrix_dense_t *TYPED_FUNC(
*/
void TYPED_FUNC(
bml_scale_dense) (
const double scale_factor,
const REAL_T * scale_factor,
const bml_matrix_dense_t * A,
bml_matrix_dense_t * B)
{
REAL_T sfactor = scale_factor;

if (A != B)
TYPED_FUNC(bml_copy_dense) (A, B);

REAL_T *B_matrix = B->matrix;
int myRank = bml_getMyRank();
//int nElems = B->N * B->N;
int nElems = B->domain->localRowExtent[myRank] * B->N;
int startIndex = B->domain->localDispl[myRank];
int inc = 1;

C_BLAS(SCAL) (&nElems, &sfactor, &(B_matrix[startIndex]), &inc);
//C_BLAS(SCAL) (&nElems, &sfactor, B->matrix, &inc);
C_BLAS(SCAL) (&nElems, scale_factor, &(B_matrix[startIndex]), &inc);
}

void TYPED_FUNC(
bml_scale_inplace_dense) (
const double scale_factor,
const REAL_T * scale_factor,
bml_matrix_dense_t * A)
{
REAL_T scale_factor_ = (REAL_T) scale_factor;
REAL_T *A_matrix = A->matrix;
int myRank = bml_getMyRank();
//int number_elements = A->N * A->N;
int number_elements = A->domain->localRowExtent[myRank] * A->N;
int startIndex = A->domain->localDispl[myRank];
int inc = 1;

C_BLAS(SCAL) (&number_elements, &scale_factor_, &(A_matrix[startIndex]),
C_BLAS(SCAL) (&number_elements, scale_factor, &(A_matrix[startIndex]),
&inc);
//C_BLAS(SCAL) (&number_elements, &scale_factor_, A->matrix, &inc);
}
4 changes: 2 additions & 2 deletions src/C-interface/ellpack/bml_normalize_ellpack_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ void TYPED_FUNC(
{
double maxminusmin = maxeval - mineval;
double gershfact = maxeval / maxminusmin;
double scalar = (double) -1.0 / maxminusmin;
REAL_T scalar = (REAL_T) - 1.0 / maxminusmin;
double threshold = 0.0;

bml_scale_inplace_ellpack(scalar, A);
bml_scale_inplace_ellpack(&scalar, A);
bml_add_identity_ellpack(A, gershfact, threshold);
}

Expand Down
6 changes: 3 additions & 3 deletions src/C-interface/ellpack/bml_scale_ellpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
bml_matrix_ellpack_t *
bml_scale_ellpack_new(
const double scale_factor,
const void * scale_factor,
const bml_matrix_ellpack_t * A)
{
bml_matrix_ellpack_t *B = NULL;
Expand Down Expand Up @@ -51,7 +51,7 @@ bml_scale_ellpack_new(
*/
void
bml_scale_ellpack(
const double scale_factor,
const void * scale_factor,
const bml_matrix_ellpack_t * A,
const bml_matrix_ellpack_t * B)
{
Expand All @@ -77,7 +77,7 @@ bml_scale_ellpack(

void
bml_scale_inplace_ellpack(
const double scale_factor,
const void * scale_factor,
bml_matrix_ellpack_t * A)
{
switch (A->matrix_precision)
Expand Down
Loading

0 comments on commit b124eda

Please sign in to comment.