Skip to content

Commit b8fa0c3

Browse files
author
Alessandro Fanfarillo
committed
End team implemented
1 parent 5967d92 commit b8fa0c3

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
/* Linked list of static coarrays registered. */
@@ -285,6 +294,7 @@ void PREFIX (fail_image) (void) __attribute__ ((noreturn));
285294

286295
void PREFIX (form_team) (int, caf_team_t *, int);
287296
void PREFIX (change_team) (caf_team_t *, int);
297+
void PREFIX (end_team) (caf_team_t *);
288298

289299
int PREFIX (image_status) (int);
290300
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>
@@ -174,7 +175,7 @@ char err_buffer[MPI_MAX_ERROR_STRING];
174175
MPI_Comm CAF_COMM_WORLD;
175176

176177
static caf_teams_list *teams_list = NULL;
177-
static MPI_Comm current_team;
178+
static caf_used_teams_list *used_teams = NULL;
178179

179180
#ifdef WITH_FAILED_IMAGES
180181
/* The stati of the other images. image_stati is an array of size
@@ -757,7 +758,15 @@ PREFIX (init) (int *argc, char ***argv)
757758

758759
stat_tok = malloc (sizeof (MPI_Win));
759760

760-
current_team = CAF_COMM_WORLD;
761+
teams_list = (caf_teams_list *)calloc(1,sizeof(caf_teams_list));
762+
teams_list->team_id = INT_MIN;
763+
MPI_Comm *tmp_comm = (MPI_Comm *)calloc(1,sizeof(MPI_Comm));
764+
*tmp_comm = CAF_COMM_WORLD;
765+
teams_list->team = tmp_comm;
766+
teams_list->prev = NULL;
767+
used_teams = (caf_used_teams_list *)calloc(1,sizeof(caf_used_teams_list));
768+
used_teams->team_list_elem = teams_list;
769+
used_teams->prev = NULL;
761770

762771
#ifdef WITH_FAILED_IMAGES
763772
MPI_Comm_dup (MPI_COMM_WORLD, &alive_comm);
@@ -4812,7 +4821,7 @@ void PREFIX (form_team) (int team_id, caf_team_t *team, int index __attribute__
48124821
struct caf_teams_list *tmp;
48134822
void * tmp_team;
48144823
MPI_Comm *newcomm;
4815-
MPI_Comm *current_comm = &current_team;
4824+
MPI_Comm *current_comm = &CAF_COMM_WORLD;
48164825

48174826
MPI_Barrier(CAF_COMM_WORLD);
48184827
newcomm = (MPI_Comm *)calloc(1,sizeof(MPI_Comm));
@@ -4828,22 +4837,65 @@ void PREFIX (form_team) (int team_id, caf_team_t *team, int index __attribute__
48284837

48294838
void PREFIX (change_team) (caf_team_t *team, int coselector __attribute__ ((unused)))
48304839
{
4840+
caf_used_teams_list *tmp_used = NULL;
4841+
caf_teams_list * tmp_list = NULL;
48314842
void *tmp_team;
48324843
MPI_Comm *tmp_comm;
4844+
48334845
MPI_Barrier(CAF_COMM_WORLD);
48344846
tmp_team = (void *)*team;
48354847
tmp_comm = (MPI_Comm *)tmp_team;
4848+
4849+
tmp_used = (caf_used_teams_list *)calloc(1,sizeof(caf_used_teams_list));
4850+
tmp_used->prev = used_teams;
4851+
4852+
/* We need to look in the teams_list and find the appropriate element.
4853+
* This is not efficient but can be easily fixed in the future.
4854+
* Instead of keeping track of the communicator in the compiler
4855+
* we should keep track of the caf_teams_list element associated with it. */
4856+
4857+
tmp_list = teams_list;
4858+
4859+
while(tmp_list)
4860+
{
4861+
if(tmp_list->team == tmp_team)
4862+
break;
4863+
tmp_list = tmp_list->prev;
4864+
}
4865+
4866+
if(tmp_list == NULL)
4867+
caf_runtime_error("CHANGE TEAM called on a non-existing team");
4868+
4869+
tmp_used->team_list_elem = tmp_list;
4870+
used_teams = tmp_used;
4871+
tmp_team = tmp_used->team_list_elem->team;
4872+
tmp_comm = (MPI_Comm *)tmp_team;
48364873
CAF_COMM_WORLD = *tmp_comm;
48374874
MPI_Comm_rank(*tmp_comm,&caf_this_image);
48384875
caf_this_image++;
48394876
MPI_Comm_size(*tmp_comm,&caf_num_images);
4840-
4841-
/* MPI_Comm_split(*current_comm, team_id, caf_this_image, &newcomm); */
4842-
4843-
/* tmp = calloc(1,sizeof(struct caf_teams_list)); */
4844-
/* tmp->prev = teams_list; */
4845-
/* teams_list = tmp; */
4846-
/* teams_list->team_id = team_id; */
4847-
/* teams_list->team = &newcomm; */
4848-
/* *team = &newcomm; */
4877+
}
4878+
4879+
void PREFIX (end_team) (caf_team_t *team __attribute__ ((unused)))
4880+
{
4881+
caf_used_teams_list *tmp_used = NULL;
4882+
void *tmp_team;
4883+
MPI_Comm *tmp_comm;
4884+
4885+
MPI_Barrier(CAF_COMM_WORLD);
4886+
if(used_teams->prev == NULL)
4887+
caf_runtime_error("END TEAM called on initial team");
4888+
4889+
tmp_used = used_teams;
4890+
used_teams = used_teams->prev;
4891+
free(tmp_used);
4892+
tmp_used = used_teams;
4893+
tmp_team = tmp_used->team_list_elem->team;
4894+
tmp_comm = (MPI_Comm *)tmp_team;
4895+
CAF_COMM_WORLD = *tmp_comm;
4896+
MPI_Barrier(CAF_COMM_WORLD);
4897+
/* CAF_COMM_WORLD = (MPI_Comm)*tmp_used->team_list_elem->team; */
4898+
MPI_Comm_rank(CAF_COMM_WORLD,&caf_this_image);
4899+
caf_this_image++;
4900+
MPI_Comm_size(CAF_COMM_WORLD,&caf_num_images);
48494901
}

0 commit comments

Comments
 (0)