@@ -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>
@@ -174,7 +175,7 @@ char err_buffer[MPI_MAX_ERROR_STRING];
174
175
MPI_Comm CAF_COMM_WORLD ;
175
176
176
177
static caf_teams_list * teams_list = NULL ;
177
- static MPI_Comm current_team ;
178
+ static caf_used_teams_list * used_teams = NULL ;
178
179
179
180
#ifdef WITH_FAILED_IMAGES
180
181
/* The stati of the other images. image_stati is an array of size
@@ -757,7 +758,15 @@ PREFIX (init) (int *argc, char ***argv)
757
758
758
759
stat_tok = malloc (sizeof (MPI_Win ));
759
760
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 ;
761
770
762
771
#ifdef WITH_FAILED_IMAGES
763
772
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__
4812
4821
struct caf_teams_list * tmp ;
4813
4822
void * tmp_team ;
4814
4823
MPI_Comm * newcomm ;
4815
- MPI_Comm * current_comm = & current_team ;
4824
+ MPI_Comm * current_comm = & CAF_COMM_WORLD ;
4816
4825
4817
4826
MPI_Barrier (CAF_COMM_WORLD );
4818
4827
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__
4828
4837
4829
4838
void PREFIX (change_team ) (caf_team_t * team , int coselector __attribute__ ((unused )))
4830
4839
{
4840
+ caf_used_teams_list * tmp_used = NULL ;
4841
+ caf_teams_list * tmp_list = NULL ;
4831
4842
void * tmp_team ;
4832
4843
MPI_Comm * tmp_comm ;
4844
+
4833
4845
MPI_Barrier (CAF_COMM_WORLD );
4834
4846
tmp_team = (void * )* team ;
4835
4847
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 ;
4836
4873
CAF_COMM_WORLD = * tmp_comm ;
4837
4874
MPI_Comm_rank (* tmp_comm ,& caf_this_image );
4838
4875
caf_this_image ++ ;
4839
4876
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 );
4849
4901
}
0 commit comments