Skip to content

Commit

Permalink
Added new functionality for mixed sparse-dense operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruce J Palmer authored and Bruce J Palmer committed Sep 13, 2024
1 parent eee52ce commit d663193
Show file tree
Hide file tree
Showing 11 changed files with 1,709 additions and 168 deletions.
1 change: 0 additions & 1 deletion global/src/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -5897,7 +5897,6 @@ double pnga_rand(Integer iseed)
{
double ret;
if (GA_Rand_seed == -1) {
printf("p[%d] Initializing GA_Rand seed: %d\n",GAme,iseed);
unsigned long lseed;
/* Choose a value for iseed if it has not already been set */
if (iseed == 0) {
Expand Down
46 changes: 37 additions & 9 deletions global/src/capi.c
Original file line number Diff line number Diff line change
Expand Up @@ -5366,6 +5366,18 @@ int NGA_Sprs_array_create64(int64_t idim, int64_t jdim, int type)
return (int)wnga_sprs_array_create(i,j,type,sizeof(int64_t));
}

int NGA_Sprs_array_create_from_dense(int g_a)
{
Integer ga = (Integer)g_a;
return (int)wnga_sprs_array_create_from_dense(ga,sizeof(int),1);
}

int NGA_Sprs_array_create_from_dense64(int g_a)
{
Integer ga = (Integer)g_a;
return (int)wnga_sprs_array_create_from_dense(ga,sizeof(int64_t),1);
}

void NGA_Sprs_array_add_element(int s_a, int idx, int jdx, void *val)
{
Integer sa = (Integer)s_a;
Expand All @@ -5385,7 +5397,7 @@ void NGA_Sprs_array_add_element64(int s_a, int64_t idx, int64_t jdx, void *val)
int NGA_Sprs_array_assemble(int s_a)
{
Integer sa = (Integer)s_a;
wnga_sprs_array_assemble(sa);
return wnga_sprs_array_assemble(sa);
}

void NGA_Sprs_array_row_distribution(int s_a, int iproc, int *lo, int *hi)
Expand Down Expand Up @@ -5559,6 +5571,22 @@ int NGA_Sprs_array_matmat_multiply(int s_a, int s_b)
return (int)wnga_sprs_array_matmat_multiply(sa, sb);
}

int NGA_Sprs_array_sprsdns_multiply(int s_a, int g_b)
{
int g_c;
Integer sa = (Integer)s_a;
Integer gb = (Integer)g_b;
return (int)wnga_sprs_array_sprsdns_multiply(sa, gb, 1);
}

int NGA_Sprs_array_dnssprs_multiply(int g_a, int s_b)
{
int g_c;
Integer ga = (Integer)g_a;
Integer sb = (Integer)s_b;
return (int)wnga_sprs_array_dnssprs_multiply(ga, sb, 1);
}

int NGA_Sprs_array_count_sketch(int s_a, int size_k, int *g_k, int *g_w)
{
Integer sa = (Integer)s_a;
Expand All @@ -5571,16 +5599,16 @@ int NGA_Sprs_array_count_sketch(int s_a, int size_k, int *g_k, int *g_w)
return ret;
}

int NGA_Sprs_array_get_column(int g_v, int irow)
int NGA_Sprs_array_get_column(int s_a, int icol)
{
Integer gv = (Integer)g_v;
Integer ir = (Integer)irow;
return (int)wnga_sprs_array_get_column(gv, ir);
Integer sa = (Integer)s_a;
Integer ic = (Integer)icol;
return (int)wnga_sprs_array_get_column(sa, ic);
}

int NGA_Sprs_array_get_column64(int g_v, int64_t irow)
int NGA_Sprs_array_get_column64(int s_a, int64_t icol)
{
Integer gv = (Integer)g_v;
Integer ir = (Integer)irow;
return (int)wnga_sprs_array_get_column(gv, ir);
Integer sa = (Integer)s_a;
Integer ic = (Integer)icol;
return (int)wnga_sprs_array_get_column(sa, ic);
}
3 changes: 3 additions & 0 deletions global/src/cnames.h
Original file line number Diff line number Diff line change
Expand Up @@ -3196,6 +3196,7 @@
#define nga_sput_field_ F77_FUNC_(nga_sput_field,NGA_SPUT_FIELD)
#define nga_zput_field_ F77_FUNC_(nga_zput_field,NGA_ZPUT_FIELD)
#define nga_sprs_array_create_ F77_FUNC_(nga_sprs_array_create,NGA_SPRS_ARRAY_CREATE)
#define nga_sprs_array_create_from_dense_ F77_FUNC_(nga_sprs_array_create_from_dense,NGA_SPRS_ARRAY_CREATE_FROM_DENSE)
#define nga_sprs_array_add_element_ F77_FUNC_(nga_sprs_array_add_element,NGA_SPRS_ARRAY_ADD_ELEMENT)
#define nga_sprs_array_assemble_ F77_FUNC_(nga_sprs_array_assemble,NGA_SPRS_ARRAY_ASSEMBLE)
#define nga_sprs_array_row_distribution_ F77_FUNC_(nga_sprs_array_row_distribution,NGA_SPRS_ARRAY_ROW_DISTRIBUTION)
Expand All @@ -3210,6 +3211,8 @@
#define nga_sprs_array_shift_diag_ F77_FUNC_(nga_sprs_array_shift_diag,NGA_SPRS_ARRAY_SHIFT_DIAG)
#define nga_sprs_array_duplicate_ F77_FUNC_(nga_sprs_array_duplicate,NGA_SPRS_ARRAY_DUPLICATE)
#define nga_sprs_array_matmat_multiply_ F77_FUNC_(nga_sprs_array_matmat_multiply,NGA_SPRS_ARRAY_MATMAT_MULTIPLY)
#define nga_sprs_array_sprsdns_multiply_ F77_FUNC_(nga_sprs_array_sprsdns_multiply,NGA_SPRS_ARRAY_SPRSDNS_MULTIPLY)
#define nga_sprs_array_dnssprs_multiply_ F77_FUNC_(nga_sprs_array_dnssprs_multiply,NGA_SPRS_ARRAY_DNSSPRS_MULTIPLY)
#define nga_sprs_array_count_sketch_ F77_FUNC_(nga_sprs_array_count_sketch,NGA_SPRS_ARRAY_COUNT_SKETCH)
/* the missing functions are either complex type or strangely named */

Expand Down
17 changes: 16 additions & 1 deletion global/src/fapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -3768,6 +3768,11 @@ Integer nga_sprs_array_create_(Integer *idim, Integer *jdim, Integer *type)
return wnga_sprs_array_create(*idim,*jdim,ctype,sizeof(Integer));
}

Integer nga_sprs_array_create_from_dense_(Integer *g_a)
{
return wnga_sprs_array_create_from_dense(*g_a,sizeof(Integer),0);
}

void nga_sprs_array_add_element_(Integer *s_a, Integer *idx, Integer *jdx, void *val)
{
wnga_sprs_array_add_element(*s_a,*idx,*jdx,val);
Expand Down Expand Up @@ -3799,7 +3804,7 @@ void nga_sprs_array_access_col_block_(Integer *s_a, Integer *icol,
void nga_sprs_array_col_block_list_(Integer *s_a, Integer *idx, Integer *n)
{
/* This function assumes that idx has already been allocated by calling
* program and that n is the length of idx on input. On output, n is
* program and that nn is the length of idx on input. On output, nn is
* changed to the actual number of blocks found by the
* wnga_sprs_array_col_block_list function
*/
Expand Down Expand Up @@ -3864,6 +3869,16 @@ Integer nga_sprs_array_matmat_multiply_(Integer *s_a, Integer *s_b)
return wnga_sprs_array_matmat_multiply(*s_a, *s_b);
}

Integer nga_sprs_array_sprsdns_multiply_(Integer *s_a, Integer *g_b)
{
return wnga_sprs_array_sprsdns_multiply(*s_a, *g_b, 0);
}

Integer nga_sprs_array_dnssprs_multiply_(Integer *g_a, Integer *s_b)
{
return wnga_sprs_array_dnssprs_multiply(*g_a, *s_b, 0);
}

Integer nga_sprs_array_count_sketch_(Integer *s_a, Integer *size_k, Integer *g_k,
Integer *g_w)
{
Expand Down
5 changes: 4 additions & 1 deletion global/src/ga-papi.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ extern void pnga_put_field(Integer g_a, Integer *lo, Integer *hi, Integer foff,

/* Routines for sparse matrices */

extern Integer pnga_sprs_array_create(Integer idim, Integer jdim, Integer type, Integer size);
extern Integer pnga_sprs_array_create(Integer idim, Integer jdim, Integer type, Integer trans);
extern Integer pnga_sprs_array_create_from_dense(Integer g_a, Integer idxsize, Integer flag);
extern void pnga_sprs_array_add_element(Integer s_a, Integer idx, Integer jdx, void *val);
extern logical pnga_sprs_array_assemble(Integer s_a);
extern void pnga_sprs_array_row_distribution(Integer s_a, Integer iproc, Integer *lo, Integer *hi);
Expand All @@ -410,6 +411,8 @@ extern int pnga_sprs_array_access_col_block_idx(Integer s_a, Integer icol, Acces
extern void pnga_sprs_array_col_block_list(Integer s_a, Integer **idx, Integer *n);
extern Integer pnga_sprs_array_duplicate(Integer s_a);
extern Integer pnga_sprs_array_matmat_multiply(Integer s_a, Integer s_b);
extern Integer pnga_sprs_array_sprsdns_multiply(Integer s_a, Integer g_b, Integer trans);
extern Integer pnga_sprs_array_dnssprs_multiply(Integer g_a, Integer s_b, Integer trans);
extern Integer pnga_sprs_array_count_sketch(Integer s_a, Integer size_k,
Integer *g_k, Integer *g_w, Integer trans);
extern void pnga_sprs_array_matvec_multiply(Integer s_a, Integer g_a, Integer g_v);
Expand Down
4 changes: 4 additions & 0 deletions global/src/ga.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,14 @@ extern void NGA_Sprs_array_access_col_block64(int s_a, int icol, long *
extern void NGA_Sprs_array_add_element(int s_a, int idx, int jdx, void *val);
extern int NGA_Sprs_array_assemble(int s_a);
extern int NGA_Sprs_array_create(int idim, int jdim, int type);
extern int NGA_Sprs_array_create_from_dense(int g_a);
extern void NGA_Sprs_array_column_distribution(int s_a, int iproc, int *lo, int *hi);
extern void NGA_Sprs_array_col_block_list(int s_a, int **idx, int *n);
extern int NGA_Sprs_array_count_sketch(int s_a, int size_k, int *g_k, int* g_w);
extern int NGA_Sprs_array_destroy(int s_a);
extern void NGA_Sprs_array_diag_right_multiply(int s_a, int g_d);
extern void NGA_Sprs_array_diag_left_multiply(int s_a, int g_d);
extern int NGA_Sprs_array_dnssprs_multiply(int g_a, int s_b);
extern int NGA_Sprs_array_duplicate(int s_a);
extern void NGA_Sprs_array_export(int s_a, const char* file);
extern int NGA_Sprs_array_get_block(int s_a, int irow, int icol,
Expand All @@ -375,6 +377,7 @@ extern int NGA_Sprs_array_matmat_multiply(int s_a, int s_b);
extern void NGA_Sprs_array_matvec_multiply(int s_a, int g_a, int g_v);
extern void NGA_Sprs_array_row_distribution(int s_a, int iproc, int *lo, int *hi);
extern void NGA_Sprs_array_shift_diag(int s_a, void *shift);
extern int NGA_Sprs_array_sprsdns_multiply(int s_a, int g_b);
extern void NGA_Strided_acc(int g_a, int lo[], int hi[], int skip[], void* buf, int ld[], void *alpha);
extern void NGA_Strided_get(int g_a, int lo[], int hi[], int skip[], void* buf, int ld[]);
extern void NGA_Strided_put(int g_a, int lo[], int hi[], int skip[], void* buf, int ld[]);
Expand Down Expand Up @@ -497,6 +500,7 @@ extern void NGA_Strided_put64(int g_a, int64_t lo[], int64_t hi[], int6
extern DoubleComplex NGA_Zdot_patch64(int g_a, char t_a, int64_t alo[], int64_t ahi[], int g_b, char t_b, int64_t blo[], int64_t bhi[]);
extern void NGA_Zero_patch64(int g_a, int64_t lo[], int64_t hi[]);
extern int NGA_Sprs_array_create64(int64_t idim, int64_t jdim, int type);
extern int NGA_Sprs_array_create_from_dense64(int g_a);
extern void NGA_Sprs_array_add_element64(int s_a, int64_t idx, int64_t jdx, void *val);
extern void NGA_Sprs_array_row_distribution64(int s_a, int iproc, int64_t *lo, int64_t *hi);
extern void NGA_Sprs_array_column_distribution64(int s_a, int iproc, int64_t *lo, int64_t *hi);
Expand Down
1 change: 1 addition & 0 deletions global/src/ga_sparse.array.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ typedef struct {
Integer idx_size; /* size of integer indices */
Integer grp; /* handle for process group on which array is defined */
Integer ilo, ihi; /* minimum and maximum row indices contained on this process */
/* ilo and ihi are zero-based */
Integer nprocs; /* number of processors containing this array */
Integer nblocks; /* number of non-zero sparse blocks contained on this process */
Integer *blkidx; /* array containing indices of non-zero blocks */
Expand Down
8 changes: 8 additions & 0 deletions global/src/global.fh.in
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,12 @@
integer nga_spd_invert
logical nga_sprs_array_assemble
integer nga_sprs_array_create
integer nga_sprs_array_create_from_dense
integer nga_sprs_array_duplicate
logical nga_sprs_array_destroy
integer nga_sprs_array_dnssprs_multiply
integer nga_sprs_array_matmat_multiply
integer nga_sprs_array_sprsdns_multiply
integer nga_total_blocks
logical nga_update2_ghosts
logical nga_update3_ghosts
Expand Down Expand Up @@ -302,8 +306,12 @@
external nga_spd_invert
external nga_sprs_array_assemble
external nga_sprs_array_create
external nga_sprs_array_create_from_dense
external nga_sprs_array_duplicate
external nga_sprs_array_destroy
external nga_sprs_array_dnssprs_multiply
external nga_sprs_array_matmat_multiply
external nga_sprs_array_sprsdns_multiply
external nga_total_blocks
external nga_update2_ghosts
external nga_update3_ghosts
Expand Down
Loading

0 comments on commit d663193

Please sign in to comment.