Nek5000
SEM for Incompressible NS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
gs_test_old.c
Go to the documentation of this file.
1 /* simple stand-alone test for parallel gather-scatter routines
2  assumes gather-scatter routines were compiled with default names
3  can compile to sequential version if MPI is not defined
4 
5  the test is as follows, where N is the number of procs:
6  there are N physical nodes (vertices)
7  each proc has 2 local/virtual nodes mapping to each physical node,
8  for a total of 2*N*N virtual nodes
9  virtual nodes are given values that correspond to a sequential ordering
10  (so that they range from 0 to 2*N*N-1)
11  the addition operation is performed and the result is checked,
12  the correct result being known a priori
13  the addition operation is also checked, in a similar manner, for
14  both the cpgs_op_vec and cpgs_op_many routines with vector dimension 3
15 */
16 
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <math.h>
20 #ifdef MPI
21 # include <mpi.h>
22 #else
23  typedef void MPI_Comm;
24 #endif
25 #include "name.h"
26 #include "types.h"
27 
28 typedef long real;
30 
31 #define fgs_setup FORTRAN_NAME(gs_setup ,GS_SETUP )
32 #define fgs_op FORTRAN_NAME(gs_op ,GS_OP )
33 #define fgs_op_vec FORTRAN_NAME(gs_op_vec ,GS_OP_VEC )
34 #define fgs_op_many FORTRAN_NAME(gs_op_many ,GS_OP_MANY )
35 #define fgs_op_fields FORTRAN_NAME(gs_op_fields,GS_OP_FIELDS)
36 #define fgs_free FORTRAN_NAME(gs_free ,GS_FREE )
37 
38 void fgs_setup(sint *handle, const slong id[], const sint *n,
39  const MPI_Comm *comm, const sint *np);
40 void fgs_op(const sint *handle, void *u, const sint *dom, const sint *op,
41  const sint *transpose);
42 void fgs_op_vec(const sint *handle, void *u, const sint *n,
43  const sint *dom, const sint *op, const sint *transpose);
44 void fgs_op_many(const sint *handle, void *u1, void *u2, void *u3,
45  void *u4, void *u5, void *u6, const sint *n,
46  const sint *dom, const sint *op, const sint *transpose);
47 void fgs_free(const sint *handle);
48 
50 {
51  if(fabs(v) < 1e-20) return;
52  printf("test failed\n");
53  exit(1);
54 }
55 
56 int main(int narg, char* arg[])
57 {
58  sint transpose=0;
59  sint id=0,np=1;
60  sint i,handle,maxv=3;
61  real *u;
62  slong *glindex;
63 #ifndef MPI
64  int comm;
65 #else
66  MPI_Comm comm;
67  MPI_Init(&narg,&arg);
68  MPI_Comm_dup(MPI_COMM_WORLD,&comm);
69  { int i;
70  MPI_Comm_rank(comm,&i); id=i;
71  MPI_Comm_size(comm,&i); np=i;
72  }
73 #endif
74 
75  glindex = malloc(np*2*sizeof(slong));
76  for(i=0;i<np;++i) glindex[2*i+1] = glindex[2*i] = i+1;
77  i=np*2;
78  fgs_setup(&handle,glindex,&i,&comm,&np);
79  free(glindex);
80 
81  u = malloc(np*2*sizeof(real));
82  for(i=0;i<np;++i) u[2*i ] = (real)( 2*np*id + 2*i ),
83  u[2*i+1] = (real)( 2*np*id + 2*i+1 );
84  /*for(i=0;i<np;++i) printf(" (%g %g)", u[2*i], u[2*i+1]); printf("\n");*/
85  i=1, fgs_op(&handle,u,&datatype,&i,&transpose);
86  /*for(i=0;i<np;++i) printf(" (%g %g)", u[2*i], u[2*i+1]); printf("\n");*/
87  for(i=0;i<np;++i) assert_is_zero( np*(2*np*(np-1)+4*i+1) - u[2*i] ),
88  assert_is_zero( np*(2*np*(np-1)+4*i+1) - u[2*i+1] );
89  free(u);
90 
91  u = malloc(np*2*3*sizeof(real));
92  for(i=0;i<np;++i)
93  u[3*(2*i )+0] = (real)( 3*(2*np*id + 2*i ) + 0 ),
94  u[3*(2*i )+1] = (real)( 3*(2*np*id + 2*i ) + 1 ),
95  u[3*(2*i )+2] = (real)( 3*(2*np*id + 2*i ) + 2 ),
96  u[3*(2*i+1)+0] = (real)( 3*(2*np*id + 2*i+1) + 0 ),
97  u[3*(2*i+1)+1] = (real)( 3*(2*np*id + 2*i+1) + 1 ),
98  u[3*(2*i+1)+2] = (real)( 3*(2*np*id + 2*i+1) + 2 );
99  /*for(i=0;i<np;++i) {
100  int j;
101  printf("%d: ( ", id);
102  for(j=3*(2*i);j<=3*(2*i+1)+2;++j) printf("%g ",u[j]);
103  printf(")\n");
104  }*/
105  i=1, maxv=3, fgs_op_vec(&handle,u,&maxv,&datatype,&i,&transpose);
106  /*for(i=0;i<np;++i) {
107  int j;
108  printf("%d: ( ", id);
109  for(j=3*(2*i);j<=3*(2*i+1)+2;++j) printf("%g ",u[j]);
110  printf(")\n");
111  }*/
112  for(i=0;i<np;++i)
113  assert_is_zero( np*(6*np*(np-1)+12*i+3+2*0) - u[3*(2*i )+0] ),
114  assert_is_zero( np*(6*np*(np-1)+12*i+3+2*1) - u[3*(2*i )+1] ),
115  assert_is_zero( np*(6*np*(np-1)+12*i+3+2*2) - u[3*(2*i )+2] ),
116  assert_is_zero( np*(6*np*(np-1)+12*i+3+2*0) - u[3*(2*i+1)+0] ),
117  assert_is_zero( np*(6*np*(np-1)+12*i+3+2*1) - u[3*(2*i+1)+1] ),
118  assert_is_zero( np*(6*np*(np-1)+12*i+3+2*2) - u[3*(2*i+1)+2] );
119  free(u);
120 
121  u = malloc(np*2*3*sizeof(real));
122  for(i=0;i<np;++i)
123  u[2*np*0+(2*i )] = (real)( 3*(2*np*id + 2*i ) + 0 ),
124  u[2*np*1+(2*i )] = (real)( 3*(2*np*id + 2*i ) + 1 ),
125  u[2*np*2+(2*i )] = (real)( 3*(2*np*id + 2*i ) + 2 ),
126  u[2*np*0+(2*i+1)] = (real)( 3*(2*np*id + 2*i+1) + 0 ),
127  u[2*np*1+(2*i+1)] = (real)( 3*(2*np*id + 2*i+1) + 1 ),
128  u[2*np*2+(2*i+1)] = (real)( 3*(2*np*id + 2*i+1) + 2 );
129  i=1, maxv=3, fgs_op_many(&handle,u,u+2*np,u+4*np,0,0,0,&maxv,
130  &datatype,&i,&transpose);
131  for(i=0;i<np;++i)
132  assert_is_zero( np*(6*np*(np-1)+12*i+3+2*0) - u[2*np*0+(2*i )] ),
133  assert_is_zero( np*(6*np*(np-1)+12*i+3+2*1) - u[2*np*1+(2*i )] ),
134  assert_is_zero( np*(6*np*(np-1)+12*i+3+2*2) - u[2*np*2+(2*i )] ),
135  assert_is_zero( np*(6*np*(np-1)+12*i+3+2*0) - u[2*np*0+(2*i+1)] ),
136  assert_is_zero( np*(6*np*(np-1)+12*i+3+2*1) - u[2*np*1+(2*i+1)] ),
137  assert_is_zero( np*(6*np*(np-1)+12*i+3+2*2) - u[2*np*2+(2*i+1)] );
138  free(u);
139 
140  fgs_free(&handle);
141  printf("test on node %d/%d succeeded\n", (int)id+1, (int)np);
142 #ifdef MPI
143  MPI_Comm_free(&comm);
144  MPI_Finalize();
145 #endif
146  return 0;
147 }
#define slong
Definition: types.h:74
#define sint
Definition: types.h:69
#define fgs_op_vec
Definition: gs_test_old.c:33
void MPI_Comm
Definition: gs_test_old.c:23
n
Definition: xxt_test.m:73
long real
Definition: gs_test_old.c:28
#define fgs_op_many
Definition: gs_test_old.c:34
void assert_is_zero(real v)
Definition: gs_test_old.c:49
Definition: comm.h:85
int main(int narg, char *arg[])
Definition: gs_test_old.c:56
#define fgs_free
Definition: gs_test_old.c:36
const gs_dom dom
Definition: gs_test.c:15
sint datatype
Definition: gs_test_old.c:29
for i
Definition: xxt_test.m:74
#define fgs_op
Definition: gs_test_old.c:32
#define fgs_setup
Definition: gs_test_old.c:31
establishes some macros to establish naming conventions
static uint np
Definition: findpts_test.c:63