A freeze group can now be allowed to move rigidly in some dimension by using "freezed...
[gromacs/rigid-bodies.git] / src / gmxlib / thread_mpi / tmpi_ops.h
blobbba8ba4e55de1ff0d2c246828bff7f457dbf55c6
1 /*
2 This source code file is part of thread_mpi.
3 Written by Sander Pronk, Erik Lindahl, and possibly others.
5 Copyright (c) 2009, Sander Pronk, Erik Lindahl.
6 All rights reserved.
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 1) Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2) Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15 3) Neither the name of the copyright holders nor the
16 names of its contributors may be used to endorse or promote products
17 derived from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY US ''AS IS'' AND ANY
20 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL WE BE LIABLE FOR ANY
23 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 If you want to redistribute modifications, please consider that
31 scientific software is very special. Version control is crucial -
32 bugs must be traceable. We will be happy to consider code for
33 inclusion in the official distribution, but derived work should not
34 be called official thread_mpi. Details are found in the README & COPYING
35 files.
39 #ifdef THREAD_MPI_OPS
41 /* cpp wizardry follows...
43 This file is #included directly from thread_mpi.c, and constructs
44 MPI_Reduce operators.
46 What this does is create the min, max, sum, prod, etc. functions for a given
47 datatype (pre-defined as TYPE, with identifier name TYPENM) and puts pointers
48 to these functions in an array called oplist_TYPENM.
50 gmx_thread_mpi_reduce.c includes this file once for each type used by MPI,
51 and thus builds up a set of arrays of function pointers, that then get used
52 in the mpi_datatype_ structure. This way, each operation/datatype entry
53 that makes sense can be extracted easily. Note that we don't (yet) support
54 user-defined ops */
56 #define FNAMEr(tp,fn) tMPI_##tp##_##fn
57 #define FNAME(tp,fn) FNAMEr(tp,fn)
59 /* macros to define functions and prototypes based on a name and an operation */
60 #define FNr(tp,fname,fn) \
61 static void tMPI_##tp##_##fname (void *dest, void *src_a, void *src_b, \
62 int count) \
63 { \
64 /*printf("in function %s, count=%d\n", __FUNCTION__, count);*/\
65 TYPE *a=(TYPE*)src_a; \
66 TYPE *b=(TYPE*)src_b; \
67 TYPE *d=(TYPE*)dest; \
68 int i; \
69 for(i=0;i<count;i++) \
70 d[i]=(TYPE)(fn(a[i],b[i])); \
73 #define FN(tp,fname,fn) FNr(tp,fname,fn)
75 #define OPFNr(tp,fname,operator) \
76 static void tMPI_##tp##_##fname (void *dest, void *src_a, void *src_b, \
77 int count) \
78 { \
79 /*printf("in function %s, count=%d\n", __FUNCTION__, count);*/\
80 TYPE *a=(TYPE*)src_a; \
81 TYPE *b=(TYPE*)src_b; \
82 TYPE *d=(TYPE*)dest; \
83 int i; \
84 for(i=0;i<count;i++) \
85 d[i]=(TYPE)(a[i] operator b[i]); \
88 #define OPFN(tp,fname,operator) OPFNr(tp,fname,operator)
91 /* these are the function prototypes + definitions: */
92 #define MAX(a, b) (( (a) > (b) ) ? (a) : (b))
93 FN(TYPENM,max,MAX)
94 #undef MAX
95 #define MIN(a, b) (( (a) < (b) ) ? (a) : (b))
96 FN(TYPENM,min,MIN)
97 #undef MIN
98 OPFN(TYPENM,sum,+)
99 OPFN(TYPENM,prod,*)
100 #if INTTYPE!=0
101 OPFN(TYPENM,land,&&)
102 OPFN(TYPENM,band,&)
103 OPFN(TYPENM,lor,||)
104 OPFN(TYPENM,bor,|)
105 OPFN(TYPENM,bxor,^)
106 #define XOR(a, b) ( (!a) ^ (!b) )
107 FN(TYPENM,lxor,XOR)
108 #undef XOR
109 #endif
111 #define OPARRAYr(tp) oplist_##tp
112 #define OPARRAY(tp) OPARRAYr(tp)
114 tMPI_Op_fn OPARRAY(TYPENM)[] = {
115 FNAME(TYPENM,max),
116 FNAME(TYPENM,min),
117 FNAME(TYPENM,sum),
118 FNAME(TYPENM,prod),
119 #if INTTYPE
120 FNAME(TYPENM,land),
121 FNAME(TYPENM,band),
122 FNAME(TYPENM,lor),
123 FNAME(TYPENM,bor),
124 FNAME(TYPENM,lxor),
125 FNAME(TYPENM,bxor)
126 #else
133 #endif
137 #undef FNAME
138 #undef FNAMEr
139 #undef OPARRAYr
140 #undef OPARRAY
141 #undef FN
142 #undef FNr
143 #undef OPFN
144 #undef OPFNr
146 #undef TYPE
147 #undef TYPENM
148 #undef INTTYPE
150 #endif