@@ -44,6 +44,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
44
44
#include <mpi.h>
45
45
#include <pthread.h>
46
46
#include <signal.h> /* For raise */
47
+ #include <limits.h>
47
48
48
49
#ifdef HAVE_MPI_EXT_H
49
50
#include <mpi-ext.h>
@@ -215,7 +216,7 @@ char err_buffer[MPI_MAX_ERROR_STRING];
215
216
MPI_Comm CAF_COMM_WORLD ;
216
217
217
218
static caf_teams_list * teams_list = NULL ;
218
- static MPI_Comm current_team ;
219
+ static caf_used_teams_list * used_teams = NULL ;
219
220
220
221
#ifdef WITH_FAILED_IMAGES
221
222
/* The stati of the other images. image_stati is an array of size
@@ -798,7 +799,15 @@ PREFIX (init) (int *argc, char ***argv)
798
799
799
800
stat_tok = malloc (sizeof (MPI_Win ));
800
801
801
- current_team = CAF_COMM_WORLD ;
802
+ teams_list = (caf_teams_list * )calloc (1 ,sizeof (caf_teams_list ));
803
+ teams_list -> team_id = INT_MIN ;
804
+ MPI_Comm * tmp_comm = (MPI_Comm * )calloc (1 ,sizeof (MPI_Comm ));
805
+ * tmp_comm = CAF_COMM_WORLD ;
806
+ teams_list -> team = tmp_comm ;
807
+ teams_list -> prev = NULL ;
808
+ used_teams = (caf_used_teams_list * )calloc (1 ,sizeof (caf_used_teams_list ));
809
+ used_teams -> team_list_elem = teams_list ;
810
+ used_teams -> prev = NULL ;
802
811
803
812
#ifdef WITH_FAILED_IMAGES
804
813
MPI_Comm_dup (MPI_COMM_WORLD , & alive_comm );
@@ -5170,7 +5179,7 @@ void PREFIX (form_team) (int team_id, caf_team_t *team, int index __attribute__
5170
5179
struct caf_teams_list * tmp ;
5171
5180
void * tmp_team ;
5172
5181
MPI_Comm * newcomm ;
5173
- MPI_Comm * current_comm = & current_team ;
5182
+ MPI_Comm * current_comm = & CAF_COMM_WORLD ;
5174
5183
5175
5184
MPI_Barrier (CAF_COMM_WORLD );
5176
5185
newcomm = (MPI_Comm * )calloc (1 ,sizeof (MPI_Comm ));
@@ -5186,22 +5195,65 @@ void PREFIX (form_team) (int team_id, caf_team_t *team, int index __attribute__
5186
5195
5187
5196
void PREFIX (change_team ) (caf_team_t * team , int coselector __attribute__ ((unused )))
5188
5197
{
5198
+ caf_used_teams_list * tmp_used = NULL ;
5199
+ caf_teams_list * tmp_list = NULL ;
5189
5200
void * tmp_team ;
5190
5201
MPI_Comm * tmp_comm ;
5202
+
5191
5203
MPI_Barrier (CAF_COMM_WORLD );
5192
5204
tmp_team = (void * )* team ;
5193
5205
tmp_comm = (MPI_Comm * )tmp_team ;
5206
+
5207
+ tmp_used = (caf_used_teams_list * )calloc (1 ,sizeof (caf_used_teams_list ));
5208
+ tmp_used -> prev = used_teams ;
5209
+
5210
+ /* We need to look in the teams_list and find the appropriate element.
5211
+ * This is not efficient but can be easily fixed in the future.
5212
+ * Instead of keeping track of the communicator in the compiler
5213
+ * we should keep track of the caf_teams_list element associated with it. */
5214
+
5215
+ tmp_list = teams_list ;
5216
+
5217
+ while (tmp_list )
5218
+ {
5219
+ if (tmp_list -> team == tmp_team )
5220
+ break ;
5221
+ tmp_list = tmp_list -> prev ;
5222
+ }
5223
+
5224
+ if (tmp_list == NULL )
5225
+ caf_runtime_error ("CHANGE TEAM called on a non-existing team" );
5226
+
5227
+ tmp_used -> team_list_elem = tmp_list ;
5228
+ used_teams = tmp_used ;
5229
+ tmp_team = tmp_used -> team_list_elem -> team ;
5230
+ tmp_comm = (MPI_Comm * )tmp_team ;
5194
5231
CAF_COMM_WORLD = * tmp_comm ;
5195
5232
MPI_Comm_rank (* tmp_comm ,& caf_this_image );
5196
5233
caf_this_image ++ ;
5197
5234
MPI_Comm_size (* tmp_comm ,& caf_num_images );
5198
-
5199
- /* MPI_Comm_split(*current_comm, team_id, caf_this_image, &newcomm); */
5200
-
5201
- /* tmp = calloc(1,sizeof(struct caf_teams_list)); */
5202
- /* tmp->prev = teams_list; */
5203
- /* teams_list = tmp; */
5204
- /* teams_list->team_id = team_id; */
5205
- /* teams_list->team = &newcomm; */
5206
- /* *team = &newcomm; */
5235
+ }
5236
+
5237
+ void PREFIX (end_team ) (caf_team_t * team __attribute__ ((unused )))
5238
+ {
5239
+ caf_used_teams_list * tmp_used = NULL ;
5240
+ void * tmp_team ;
5241
+ MPI_Comm * tmp_comm ;
5242
+
5243
+ MPI_Barrier (CAF_COMM_WORLD );
5244
+ if (used_teams -> prev == NULL )
5245
+ caf_runtime_error ("END TEAM called on initial team" );
5246
+
5247
+ tmp_used = used_teams ;
5248
+ used_teams = used_teams -> prev ;
5249
+ free (tmp_used );
5250
+ tmp_used = used_teams ;
5251
+ tmp_team = tmp_used -> team_list_elem -> team ;
5252
+ tmp_comm = (MPI_Comm * )tmp_team ;
5253
+ CAF_COMM_WORLD = * tmp_comm ;
5254
+ MPI_Barrier (CAF_COMM_WORLD );
5255
+ /* CAF_COMM_WORLD = (MPI_Comm)*tmp_used->team_list_elem->team; */
5256
+ MPI_Comm_rank (CAF_COMM_WORLD ,& caf_this_image );
5257
+ caf_this_image ++ ;
5258
+ MPI_Comm_size (CAF_COMM_WORLD ,& caf_num_images );
5207
5259
}
0 commit comments