Skip to content

Commit 5ac4824

Browse files
Alessandro FanfarilloDamian Rouson
authored andcommitted
End team implemented
1 parent 6cfee75 commit 5ac4824

File tree

2 files changed

+74
-12
lines changed

2 files changed

+74
-12
lines changed

src/libcaf.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,22 @@ caf_deregister_t;
9191
typedef void* caf_token_t;
9292
#ifdef GCC_GE_7
9393
/** Add a dummy type representing teams in coarrays. */
94+
9495
typedef void * caf_team_t;
96+
9597
typedef struct caf_teams_list {
9698
caf_team_t team;
9799
int team_id;
98100
struct caf_teams_list *prev;
99101
}
100102
caf_teams_list;
103+
104+
typedef struct caf_used_teams_list {
105+
struct caf_teams_list *team_list_elem;
106+
struct caf_used_teams_list *prev;
107+
}
108+
caf_used_teams_list;
109+
101110
#endif
102111

103112
/* When there is a vector subscript in this dimension, nvec == 0, otherwise,
@@ -277,6 +286,7 @@ void PREFIX (fail_image) (void) __attribute__ ((noreturn));
277286

278287
void PREFIX (form_team) (int, caf_team_t *, int);
279288
void PREFIX (change_team) (caf_team_t *, int);
289+
void PREFIX (end_team) (caf_team_t *);
280290

281291
int PREFIX (image_status) (int);
282292
void PREFIX (failed_images) (gfc_descriptor_t *, int, int *);

src/mpi/mpi_caf.c

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
4444
#include <mpi.h>
4545
#include <pthread.h>
4646
#include <signal.h> /* For raise */
47+
#include <limits.h>
4748

4849
#ifdef HAVE_MPI_EXT_H
4950
#include <mpi-ext.h>
@@ -215,7 +216,7 @@ char err_buffer[MPI_MAX_ERROR_STRING];
215216
MPI_Comm CAF_COMM_WORLD;
216217

217218
static caf_teams_list *teams_list = NULL;
218-
static MPI_Comm current_team;
219+
static caf_used_teams_list *used_teams = NULL;
219220

220221
#ifdef WITH_FAILED_IMAGES
221222
/* The stati of the other images. image_stati is an array of size
@@ -798,7 +799,15 @@ PREFIX (init) (int *argc, char ***argv)
798799

799800
stat_tok = malloc (sizeof (MPI_Win));
800801

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;
802811

803812
#ifdef WITH_FAILED_IMAGES
804813
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__
51705179
struct caf_teams_list *tmp;
51715180
void * tmp_team;
51725181
MPI_Comm *newcomm;
5173-
MPI_Comm *current_comm = &current_team;
5182+
MPI_Comm *current_comm = &CAF_COMM_WORLD;
51745183

51755184
MPI_Barrier(CAF_COMM_WORLD);
51765185
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__
51865195

51875196
void PREFIX (change_team) (caf_team_t *team, int coselector __attribute__ ((unused)))
51885197
{
5198+
caf_used_teams_list *tmp_used = NULL;
5199+
caf_teams_list * tmp_list = NULL;
51895200
void *tmp_team;
51905201
MPI_Comm *tmp_comm;
5202+
51915203
MPI_Barrier(CAF_COMM_WORLD);
51925204
tmp_team = (void *)*team;
51935205
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;
51945231
CAF_COMM_WORLD = *tmp_comm;
51955232
MPI_Comm_rank(*tmp_comm,&caf_this_image);
51965233
caf_this_image++;
51975234
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);
52075259
}

0 commit comments

Comments
 (0)