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.
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
38 #ifdef HAVE_TMPI_CONFIG_H
39 #include "tmpi_config.h"
61 /* Group query & manipulation functions */
63 bool tMPI_In_group(tMPI_Group group
)
66 struct tmpi_thread
*cur
;
68 cur
=tMPI_Get_current();
69 for(i
=0;i
<group
->N
;i
++)
71 if (group
->peers
[i
] == cur
)
77 int tMPI_Group_size(tMPI_Group group
, int *size
)
80 tMPI_Trace_print("tMPI_Group_size(%p, %p)", group
, size
);
90 int tMPI_Group_rank(tMPI_Group group
, int *rank
)
93 struct tmpi_thread
*cur
;
96 tMPI_Trace_print("tMPI_Group_rank(%p, %p)", group
, rank
);
99 return TMPI_UNDEFINED
;
101 /* search for my id in the list of peers */
102 cur
=tMPI_Get_current();
103 for(i
=0;i
<group
->N
;i
++)
105 if (group
->peers
[i
] == cur
)
111 return TMPI_UNDEFINED
;
116 tMPI_Group
tMPI_Group_alloc(void)
118 struct tmpi_group_
*ret
;
120 ret
=(struct tmpi_group_
*)tMPI_Malloc(sizeof(struct tmpi_group_
));
121 ret
->peers
=(struct tmpi_thread
**)tMPI_Malloc(
122 sizeof(struct tmpi_thread
*)*Nthreads
);
131 int tMPI_Group_free(tMPI_Group
*group
)
134 tMPI_Trace_print("tMPI_Group_free(%p)", group
);
138 free((*group
)->peers
);
144 int tMPI_Comm_group(tMPI_Comm comm
, tMPI_Group
*group
)
147 struct tmpi_group_
*ret
=tMPI_Group_alloc();
150 tMPI_Trace_print("tMPI_Comm_group(%p, %p)", comm
, group
);
153 for(i
=0;i
<comm
->grp
.N
;i
++)
155 ret
->peers
[i
]=comm
->grp
.peers
[i
];
173 int tMPI_Group_incl(tMPI_Group group
, int n
, int *ranks
, tMPI_Group
*newgroup
)
179 tMPI_Trace_print("tMPI_Group_incl(%p, %d, %p, %p, %p)", group
, n
, ranks
,
182 /* just allocate and copy */
183 ng
=tMPI_Group_alloc();
187 if (ranks
[i
] < 0 || !group
|| ranks
[i
] >= group
->N
)
189 return tMPI_Error(TMPI_COMM_WORLD
, TMPI_ERR_GROUP_RANK
);
191 ng
->peers
[i
]=group
->peers
[ranks
[i
]];