Skip to content

Commit 00a074c

Browse files
committed
support gs_float in Fortran interface and fix gs_test
1 parent e2df99f commit 00a074c

File tree

2 files changed

+34
-26
lines changed

2 files changed

+34
-26
lines changed

src/gs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ static void fgs_check_handle(sint handle, const char *func, unsigned line)
15551555
fail(1,__FILE__,line,"%s: invalid handle", func);
15561556
}
15571557

1558-
static const gs_dom fgs_dom[4] = { 0, gs_double, gs_sint, gs_slong };
1558+
static const gs_dom fgs_dom[4] = { gs_float, gs_double, gs_sint, gs_slong };
15591559

15601560
static void fgs_check_parms(sint handle, sint dom, sint op,
15611561
const char *func, unsigned line)

tests/gs_test.c

+33-25
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
#include <assert.h>
22
#include <math.h>
3+
#include <float.h>
34
#include "gslib.h"
45

56
typedef double T;
67
const gs_dom dom = gs_double;
8+
#define EPS (3*DBL_EPSILON)
9+
10+
/*
11+
typedef float T;
12+
const gs_dom dom = gs_float;
13+
#define EPS (3*FLT_EPSILON)
14+
*/
15+
16+
#define PI 3.14159265358979323846
717

818
static void test(const struct comm *comm, gs_method method)
919
{
@@ -49,48 +59,46 @@ static void test(const struct comm *comm, gs_method method)
4959

5060
/* non-blocking gs, gs_many and gs_vec */
5161
uint neighbors = 3; //max neighbors, counting ownself
52-
slong id1[neighbors];
53-
slong me = (slong)comm->id;
62+
slong *id1 = tmalloc(slong,neighbors);
63+
const slong me = (slong)comm->id;
5464
uint count=0;
5565
if(me>0) id1[count++]=me;
5666
id1[count++]=me+1;
5767
if(me<np-1) id1[count++]=me+2;
5868
neighbors=count;
5969

60-
struct gs_data *gsh1;
61-
gsh1 = gs_setup(id1,neighbors,comm,0,method,0);
62-
63-
T answer[np];
64-
if (np==1) answer[0]=1.0;
70+
double *answer = tmalloc(double,np);
71+
if (np==1) {
72+
answer[0]=1.0*PI;
73+
}
6574
else {
66-
answer[0]=answer[np-1]=2.0;
67-
for(i=1;i<np-1;i++) answer[i]=3.0;
75+
answer[0]=answer[np-1]=2.0*PI;
76+
for(i=1;i<np-1;i++) answer[i]=3.0*PI;
6877
}
6978

70-
T u[neighbors];
71-
for(i=0;i<neighbors;i++) u[i]=1.0;
79+
gsh = gs_setup(id1,neighbors,comm,0,method,0);
7280

81+
T *u = tmalloc(T,neighbors);
82+
for(i=0;i<neighbors;i++) u[i]=1.0*PI;
7383
igs(u,dom,gs_add,0,gsh,0,&handle);
7484
gs_wait(handle);
85+
for(i=0;i<neighbors;i++) assert(fabs(u[i]-answer[id1[i]-1])<EPS);
86+
free(u);
7587

76-
for(i=0;i<neighbors;i++) assert(fabs(u[i]-answer[id1[i]-1])<1e-16);
77-
78-
T w[neighbors][2];
79-
for(i=0;i<neighbors;i++) w[i][0]=1.0,w[i][1]=2.0;
80-
igs_vec(w,2,dom,gs_add,0,gsh,0,&handle);
81-
gs_wait(handle);
82-
83-
for(i=0;i<neighbors;i++) assert(fabs(w[i][0]-answer[id1[i]-1])<1e-16);
84-
for(i=0;i<neighbors;i++) assert(fabs(w[i][1]-2*answer[id1[i]-1])<1e-16);
85-
86-
T x1[neighbors], x2[neighbors];
87-
for(i=0;i<neighbors;i++) x1[i]=1.0,x2[i]=2.0;
88+
T *x1 = tmalloc(T,neighbors);
89+
T *x2 = tmalloc(T,neighbors);
90+
for(i=0;i<neighbors;i++) x1[i]=1.0*PI,x2[i]=2.0*PI;
8891
T *x[2] = {x1, x2};
8992
igs_many((void*)x,2,dom,gs_add,0,gsh,0,&handle);
9093
gs_wait(handle);
94+
for(i=0;i<neighbors;i++) assert(fabs(x1[i]-answer[id1[i]-1])<EPS);
95+
for(i=0;i<neighbors;i++) assert(fabs(x2[i]-2*answer[id1[i]-1])<EPS);
96+
free(x1);
97+
free(x2);
9198

92-
for(i=0;i<neighbors;i++) assert(fabs(x1[i]-answer[id1[i]-1])<1e-16);
93-
for(i=0;i<neighbors;i++) assert(fabs(x2[i]-2*answer[id1[i]-1])<1e-16);
99+
gs_free(gsh);
100+
free(id1);
101+
free(answer);
94102
}
95103

96104
int main(int narg, char *arg[])

0 commit comments

Comments
 (0)