Skip to content

Commit

Permalink
Merge branch 'feature/malloc' of github.com:GlobalArrays/ga into feat…
Browse files Browse the repository at this point in the history
…ure/malloc

Conflicts:
	global/src/DP.c
	global/src/ga_solve_seq.c
	global/src/ga_symmetr.c
	global/src/ghosts.c
	global/src/global.nalg.c
	global/src/global.npatch.c
	global/src/matmul.c
	global/src/onesided.c
	global/src/sparse.c
  • Loading branch information
Bruce J Palmer committed Sep 11, 2024
2 parents 57c39e8 + 1400983 commit 339b4f1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
26 changes: 10 additions & 16 deletions global/examples/lennard-jones/lennard.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ void LJ_Setup(int natoms, double **x_i, double **x_j, double **grad) {
i = gBlockSize * NDIM * 2; /* for gX_i and gX_j used in computeFG() */
j = natoms * NDIM; /* for gGrad in computeFG() */
n = i + j + SAFELIMIT; /* total memory required */
if(MA_push_get(C_DBL, n, "GA LJ bufs", (void *)&gMemHandle, &maindex))
MA_get_pointer(gMemHandle, x_i);
else GA_Error("ma_alloc_get failed",n);

*x_i = (double *) malloc(sizeof(double) * n);
*x_j = *x_i + i/2 + 1;
*grad = *x_j + i/2 + 1;
}
Expand Down Expand Up @@ -395,8 +392,8 @@ void LJ_Initialize(int natoms) {
printf(" System Volume = %f\n\n\n", pow(L, 3.0));
}
#endif

if(gMe == 0) {
GA_Sync();
// if(gMe == 0) {

int c, i, j, k, m, n, p;
double b, xSum[3] = {0.0, 0.0, 0.0};
Expand All @@ -408,9 +405,7 @@ void LJ_Initialize(int natoms) {
MA_AccessIndex maindex;

n = NDIM * natoms + 1;
if(MA_push_get(C_DBL, n, "GA LJ_Init bufs", (void *)&handle, &maindex))
MA_get_pointer(handle, &x);
else GA_Error("ma_alloc_get failed",n);
x = (double *) malloc(sizeof(double) * n);

/* Use face centered cubic (FCC) lattice for initial positions.
Find number of unit cells (c) needed to place all atoms */
Expand Down Expand Up @@ -438,7 +433,7 @@ void LJ_Initialize(int natoms) {

lo = 0;
hi = natoms*NDIM-1;
NGA_Put (g_X, &lo, &hi, x, &hi);
if(gMe == 0) NGA_Put (g_X, &lo, &hi, x, &hi);

/* Random Gaussian distribution of initial velocities */
for(i=0; i<natoms; i++)
Expand All @@ -450,11 +445,10 @@ void LJ_Initialize(int natoms) {
for(j=0; j<NDIM; j++)
x[i*NDIM + j] -= xSum[j]/natoms;

NGA_Put (g_V, &lo, &hi, x, &hi); /* velocity array */

if(!MA_pop_stack(handle)) GA_Error("LJ_Init:MA_pop_stack failed",0);
}

if(gMe == 0) NGA_Put (g_V, &lo, &hi, x, &hi); /* velocity array */
free(x);
// }
GA_Sync();
/* rescale to desired temperature */
rescaleVelocities(natoms);

Expand Down Expand Up @@ -705,7 +699,7 @@ void LJ_Solve(int natoms) {
100*(execTime-gComputeTime)/execTime);
}
#endif
if(!MA_pop_stack(gMemHandle)) GA_Error("LJ_Init:MA_pop_stack failed",0);
free(x_i);
}


Expand Down
2 changes: 2 additions & 0 deletions global/src/DP.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# include "config.h"
#endif

#if HAVE_STDLIB_H
#include <stdlib.h>
#endif

/* $Id: DP.c,v 1.14 2003-02-18 00:24:32 manoj Exp $ */
#include "global.h"
Expand Down
4 changes: 2 additions & 2 deletions global/src/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -725,14 +725,14 @@ C_Integer *map= (map_ij);\
\
candidate = (int)(scale*(elem));\
found = 0;\
if(map[candidate] <= (elem)){ /* search downward */\
if(map[candidate] <= (elem)){ /* search upward */\
b= candidate;\
while(b<(n)-1){ \
found = (map[b+1]>(elem));\
if(found)break;\
b++;\
} \
}else{ /* search upward */\
}else{ /* search downward */\
b= candidate-1;\
while(b>=0){\
found = (map[b]<=(elem));\
Expand Down
2 changes: 2 additions & 0 deletions global/src/ga_symmetr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# include "config.h"
#endif

#if HAVE_STDLIB_H
#include <stdlib.h>
#endif

/**
* Symmetrizes matrix A: A := .5 * (A+A`)
Expand Down
2 changes: 1 addition & 1 deletion global/src/matmul.c
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,7 @@ void pnga_matmul(transa, transb, alpha, beta,

if(tmp == NULL) { /*if armci malloc fails again, then get from MA */
tmp = a_ar[0] = a =(DoubleComplex*) pnga_malloc(elems,atype,
"GA mulmat bufs");
"GA mulmat bufs");
}

if(use_NB_matmul) tmp = a_ar[1] = a_ar[0] + (Ichunk*Kchunk)/factor+1;
Expand Down

0 comments on commit 339b4f1

Please sign in to comment.