aboutsummaryrefslogtreecommitdiff
path: root/src/TestSlab.c
blob: 9c6329f0c8b1afe9151e8c8838835b194f9a7ddd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <stdio.h>
#include <stdlib.h>
#include <math.h>  

#include "cctk.h"
#include "cctk_Parameters.h"
#include "cctk_Arguments.h"
#include "CactusPUGH/PUGH/src/include/pugh.h"
#include "CactusBase/IOUtil/src/ioGH.h"

#define MAX_DIM 3
#define MAX_FACE 6
#define EPS 1e-10
#define BAD -42

#define ABS(a) ((a)<0 ? -(a) : (a))

int IsPointOnProc(int dim, int *gownership, int *pnt);
int GetLocalLine(cGH *GH, 
		 int vardim, int *P_l, int *u_l, int *ds, int len_l,
		 int *locstart, int *locend, int *nlocpoints);

int CollectLocalData1D(cGH *GH, int vindex, int vtype, int vtypesize, int vtimelvl, 
		       int vdim, int *S_l, int *u_l, int ds, int len_l,
		       void **loc_dptr, int *dsize);

void TestSlab(CCTK_ARGUMENTS) {  
  DECLARE_CCTK_ARGUMENTS

  int gs[3], di[3], ds[1]; /* global start/direction/downsampling*/
  int ls[3], le[3];        /* local start/end */
  int nlocpoints;          /* number of points */
  int nprocs,iproc;        /* number of procs */
  int *c_nlocpoints;       /* collected number of points per proc (size nproc) */
  pGH *pughGH;
  int gindex;
  int vtype, vindex, vtypesize, vdim, vtimelvl;
  void *loc_dptr;

  vindex   = CCTK_VarIndex("grid::x");
  gindex   = CCTK_GroupIndexFromVarI(vindex);
  vtype    = CCTK_GroupTypeFromVarI(vindex);
  vtypesize= CCTK_VarTypeSize(vtype);
  vtimelvl = CCTK_NumTimeLevelsFromVarI (vindex) - 1;
  vdim     = CCTK_GroupDimI(gindex);
  

  gs[0]=1;
  gs[1]=5;
  gs[2]=9;
 
  di[0]= 0;
  di[1]=-1;
  di[2]=-2;
  
  ds[0]=1;

  CollectLocalData1D(cctkGH, vindex, vtype, vtypesize, vtimelvl,
		   vdim, gs, di, ds, -1, &loc_dptr, &nlocpoints);


}
   
void TestGetLocalLine(CCTK_ARGUMENTS) {  
  DECLARE_CCTK_ARGUMENTS

  int gs[3], di[3], ds[1]; /* global start/direction/downsampling*/
  int ls[3], le[3];        /* local start/end */
  int nlocpoints;          /* number of points */
  int nprocs,iproc;        /* number of procs */
  int *c_nlocpoints;       /* collected number of points per proc (size nproc) */
  pGH *pughGH; 

  pughGH = PUGH_pGH (cctkGH);

  gs[0]=1;
  gs[1]=5;
  gs[2]=9;
 
  di[0]= 0;
  di[1]=-1;
  di[2]= 2;
  
  ds[0]=1;
  
  GetLocalLine(cctkGH, 3, gs, di, ds, 4, ls, le, &nlocpoints);
  printf("TEST: local %d %d %d -> %d %d %d   TOTAL: %d\n",
	 ls[0], ls[1], ls[2], le[0], le[1], le[2], nlocpoints );
  
  nprocs = CCTK_nProcs(cctkGH);
  c_nlocpoints = (int*) malloc (nprocs*sizeof(int));
  
#ifdef CCTK_MPI
  CACTUS_MPI_ERROR(MPI_Gather(&nlocpoints, 1, PUGH_MPI_INT, c_nlocpoints, 1,
                    PUGH_MPI_INT, 0, pughGH->PUGH_COMM_WORLD));
#endif

  for (iproc=0;iproc<nprocs;iproc++)
    printf(" Proc %d : %d \n",iproc,c_nlocpoints[iproc]);

}