Nek5000
SEM for Incompressible NS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
sarray_transfer.h
Go to the documentation of this file.
1 #ifndef SARRAY_TRANSFER_H
2 #define SARRAY_TRANSFER_H
3 
4 #if !defined(CRYSTAL_H)
5 #warning "sarray_transfer.h" requires "crystal.h"
6 #endif
7 
8 /*
9  High-level interface for the crystal router.
10  Given an array of structs, transfers each to the process indicated
11  by a field of the struct, which gets set to the source process on output.
12 
13  For the dynamic "array" type, see "mem.h".
14 
15  Requires a "crystal router" object:
16 
17  struct comm c;
18  struct crystal cr;
19 
20  comm_init(&c, MPI_COMM_WORLD);
21  crystal_init(&cr, &c);
22 
23  Example sarray_transfer usage:
24 
25  struct T { ...; uint proc; ...; };
26  struct array A = null_array;
27  struct T *p, *e;
28 
29  // resize A to 100 struct T's, fill up with data
30  p = array_reserve(struct T, &A, 100), A.n=100;
31  for(e=p+A.n;p!=e;++p) {
32  ...
33  p->proc = ...;
34  ...
35  }
36 
37  // array A represents the array
38  // struct T ar[A.n] where &ar[0] == A.ptr
39  // transfer ar[i] to processor ar[i].proc for each i=0,...,A.n-1:
40 
41  sarray_transfer(struct T, A, proc,set_src, &cr);
42 
43  // now array A represents a different array with a different size
44  // struct T ar[A.n] where &ar[0] == A.ptr
45  // the ordering is arbitrary
46  // if set_src != 0, ar[i].proc is set to the proc where ar[i] came from
47  // otherwise ar[i].proc is unchanged (and == this proc id)
48 
49  // note: two calls of
50  sarray_transfer(struct T, A, proc,1, &cr);
51  // in a row should return A to its original state, up to ordering
52 
53  Cleanup:
54  array_free(&A);
55  crystal_free(&cr);
56  comm_free(&c);
57 
58  Example sarray_transfer_ext usage:
59 
60  struct T { ... };
61  struct array A;
62  uint proc[A.n];
63 
64  // array A represents the array
65  // struct T ar[A.n] where &ar[0] == A.ptr
66  // transfer ar[i] to processor proc[i] for each i=0,...,A.n-1:
67  sarray_transfer_ext(struct T, &A, proc, &cr);
68 
69  // no information is available now on where each struct came from
70 
71 */
72 
73 #define sarray_transfer_many PREFIXED_NAME(sarray_transfer_many)
74 #define sarray_transfer_ PREFIXED_NAME(sarray_transfer_ )
75 #define sarray_transfer_ext_ PREFIXED_NAME(sarray_transfer_ext_)
76 
78  struct array *const *const A, const unsigned *const size, const unsigned An,
79  const int fixed, const int ext, const int set_src, const unsigned p_off,
80  const uint *const restrict proc, const unsigned proc_stride,
81  struct crystal *const cr);
82 void sarray_transfer_(struct array *const A, const unsigned size,
83  const unsigned p_off, const int set_src,
84  struct crystal *const cr);
85 void sarray_transfer_ext_(struct array *const A, const unsigned size,
86  const uint *const proc, const unsigned proc_stride,
87  struct crystal *const cr);
88 
89 #define sarray_transfer(T,A,proc_field,set_src,cr) \
90  sarray_transfer_(A,sizeof(T),offsetof(T,proc_field),set_src,cr)
91 
92 #define sarray_transfer_ext(T,A,proc,proc_stride,cr) \
93  sarray_transfer_ext_(A,sizeof(T),proc,proc_stride,cr)
94 
95 #endif
#define uint
Definition: types.h:70
ulong A[NUM][SI]
Definition: sort_test.c:17
static struct crystal cr
Definition: findpts_test.c:75
#define sarray_transfer_many
Definition: mem.h:111
#define sarray_transfer_ext_
#define restrict
Definition: c99.h:11
#define sarray_transfer_