|
1 | 1 | #include <assert.h>
|
2 | 2 | #include <math.h>
|
| 3 | +#include <float.h> |
3 | 4 | #include "gslib.h"
|
4 | 5 |
|
5 | 6 | typedef double T;
|
6 | 7 | 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 |
7 | 17 |
|
8 | 18 | static void test(const struct comm *comm, gs_method method)
|
9 | 19 | {
|
@@ -49,48 +59,46 @@ static void test(const struct comm *comm, gs_method method)
|
49 | 59 |
|
50 | 60 | /* non-blocking gs, gs_many and gs_vec */
|
51 | 61 | 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; |
54 | 64 | uint count=0;
|
55 | 65 | if(me>0) id1[count++]=me;
|
56 | 66 | id1[count++]=me+1;
|
57 | 67 | if(me<np-1) id1[count++]=me+2;
|
58 | 68 | neighbors=count;
|
59 | 69 |
|
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 | + } |
65 | 74 | 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; |
68 | 77 | }
|
69 | 78 |
|
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); |
72 | 80 |
|
| 81 | + T *u = tmalloc(T,neighbors); |
| 82 | + for(i=0;i<neighbors;i++) u[i]=1.0*PI; |
73 | 83 | igs(u,dom,gs_add,0,gsh,0,&handle);
|
74 | 84 | gs_wait(handle);
|
| 85 | + for(i=0;i<neighbors;i++) assert(fabs(u[i]-answer[id1[i]-1])<EPS); |
| 86 | + free(u); |
75 | 87 |
|
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; |
88 | 91 | T *x[2] = {x1, x2};
|
89 | 92 | igs_many((void*)x,2,dom,gs_add,0,gsh,0,&handle);
|
90 | 93 | 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); |
91 | 98 |
|
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); |
94 | 102 | }
|
95 | 103 |
|
96 | 104 | int main(int narg, char *arg[])
|
|
0 commit comments