Line data Source code
1 : /** @file dart_team_private.c
2 : * @date 25 Aug 2014
3 : * @brief Implementations for the operations on teamlist.
4 : */
5 : #include <stdio.h>
6 : #include <dash/dart/if/dart_types.h>
7 : #include <dash/dart/if/dart_team_group.h>
8 : #include <dash/dart/mpi/dart_team_private.h>
9 :
10 :
11 : dart_team_t dart_next_availteamid;
12 :
13 : MPI_Comm dart_teams[DART_MAX_TEAM_NUMBER];
14 :
15 : #if !defined(DART_MPI_DISABLE_SHARED_WINDOWS)
16 : MPI_Comm dart_sharedmem_comm_list[DART_MAX_TEAM_NUMBER];
17 : #endif
18 :
19 : MPI_Win dart_win_lists[DART_MAX_TEAM_NUMBER];
20 :
21 : #if !defined(DART_MPI_DISABLE_SHARED_WINDOWS)
22 : int* dart_sharedmem_table[DART_MAX_TEAM_NUMBER];
23 : int dart_sharedmemnode_size[DART_MAX_TEAM_NUMBER];
24 : #endif
25 :
26 : struct dart_free_teamlist_entry
27 : {
28 : uint16_t index;
29 : struct dart_free_teamlist_entry* next;
30 : };
31 : typedef struct dart_free_teamlist_entry dart_free_entry;
32 : typedef dart_free_entry* dart_free_teamlist_ptr;
33 :
34 : dart_free_teamlist_ptr dart_free_teamlist_header;
35 :
36 : /* Structure of the allocated teamlist entry */
37 : struct dart_allocated_teamlist_entry
38 : {
39 : uint16_t index;
40 : dart_team_t allocated_teamid;
41 : };
42 : typedef struct dart_allocated_teamlist_entry dart_allocated_entry;
43 :
44 : /* This array is used to store all the correspondences between indice and teams */
45 : dart_allocated_entry dart_allocated_teamlist_array[DART_MAX_TEAM_NUMBER];
46 : /* Indicate the length of the allocated teamlist */
47 : int dart_allocated_teamlist_size;
48 :
49 4 : int dart_adapt_teamlist_init ()
50 : {
51 : int i;
52 4 : dart_free_teamlist_ptr pre = NULL;
53 : dart_free_teamlist_ptr newAllocateEntry;
54 1028 : for (i = 0; i < DART_MAX_TEAM_NUMBER; i++) {
55 1024 : newAllocateEntry =
56 : (dart_free_teamlist_ptr)malloc(sizeof (dart_free_entry));
57 1024 : newAllocateEntry -> index = i;
58 1024 : if (pre != NULL) {
59 1020 : pre -> next = newAllocateEntry;
60 : } else {
61 4 : dart_free_teamlist_header = newAllocateEntry;
62 : }
63 1024 : pre = newAllocateEntry;
64 : }
65 4 : newAllocateEntry -> next = NULL;
66 :
67 4 : dart_allocated_teamlist_size = 0;
68 4 : return 0;
69 : }
70 :
71 4 : int dart_adapt_teamlist_destroy ()
72 : {
73 4 : dart_free_teamlist_ptr pre, p = dart_free_teamlist_header;
74 1028 : while (p) {
75 1020 : pre = p;
76 1020 : p = p -> next;
77 1020 : free (pre);
78 : }
79 4 : dart_allocated_teamlist_size = 0;
80 4 : return 0;
81 : }
82 :
83 4 : int dart_adapt_teamlist_alloc (dart_team_t teamid, uint16_t* index)
84 : {
85 : dart_free_teamlist_ptr p;
86 4 : if (dart_free_teamlist_header != NULL) {
87 4 : *index = dart_free_teamlist_header -> index;
88 4 : p = dart_free_teamlist_header;
89 :
90 4 : dart_free_teamlist_header = dart_free_teamlist_header -> next;
91 4 : free (p);
92 : #if 0
93 : for (j = dart_allocated_teamlist_size - 1; (j>=0)&&(dart_allocated_teamlist_array[j].allocated_teamid > teamid); j--)
94 : {
95 : dart_allocated_teamlist_array[j + 1].index = dart_allocated_teamlist_array[j].index;
96 : dart_allocated_teamlist_array[j + 1].allocated_teamid = dart_allocated_teamlist_array[j].allocated_teamid;
97 : }
98 : dart_allocated_teamlist_array[j+1].index = *index;
99 : dart_allocated_teamlist_array[j+1].allocated_teamid = teamid;
100 : #endif
101 :
102 : /* The allocated teamlist array should be arranged in an increasing order based on
103 : * the member of allocated_teamid.
104 : *
105 : * Notes: the newly created teamid will always be increased because the teamid
106 : * is not reused after certain team is destroyed.
107 : */
108 4 : dart_allocated_teamlist_array[dart_allocated_teamlist_size].index = *index;
109 4 : dart_allocated_teamlist_array[dart_allocated_teamlist_size].allocated_teamid = teamid;
110 4 : dart_allocated_teamlist_size ++;
111 :
112 : /* If allocated successfully, the position of the new element in the allcoated array
113 : * is returned.
114 : */
115 4 : return (dart_allocated_teamlist_size - 1);
116 :
117 : } else {
118 0 : DART_LOG_ERROR ("Out of bound: exceed the MAX_TEAM_NUMBER limit");
119 0 : return -1;
120 : }
121 : }
122 :
123 0 : int dart_adapt_teamlist_recycle (uint16_t index, int pos)
124 : {
125 : int i;
126 0 : dart_free_teamlist_ptr newAllocateEntry =
127 : (dart_free_teamlist_ptr)malloc (sizeof (dart_free_entry));
128 0 : newAllocateEntry -> index = index;
129 0 : newAllocateEntry -> next = dart_free_teamlist_header;
130 0 : dart_free_teamlist_header = newAllocateEntry;
131 : /* The allocated teamlist array should be keep as an ordered array
132 : * after deleting the given element.
133 : */
134 0 : for (i = pos; i < dart_allocated_teamlist_size - 1; i ++) {
135 0 : dart_allocated_teamlist_array[i].allocated_teamid =
136 0 : dart_allocated_teamlist_array[i + 1].allocated_teamid;
137 0 : dart_allocated_teamlist_array[i].index =
138 0 : dart_allocated_teamlist_array[i + 1].index;
139 : }
140 0 : dart_allocated_teamlist_size --;
141 0 : return 0;
142 : }
143 :
144 9380 : int dart_adapt_teamlist_convert (dart_team_t teamid, uint16_t* index)
145 : {
146 9380 : if (teamid == DART_TEAM_ALL) {
147 9380 : *index = 0;
148 9380 : return 0;
149 : }
150 : /* Locate the team id in the allocated teamlist array by using the
151 : * binary-search approach.
152 : */
153 : int imin, imax;
154 0 : imin = 0;
155 0 : imax = dart_allocated_teamlist_size - 1;
156 0 : while (imin < imax) {
157 0 : int imid = (imin + imax) >> 1;
158 0 : if (dart_allocated_teamlist_array[imid].allocated_teamid < teamid) {
159 0 : imin = imid + 1;
160 : } else {
161 0 : imax = imid;
162 : }
163 : }
164 0 : if ((imax == imin) &&
165 0 : (dart_allocated_teamlist_array[imin].allocated_teamid == teamid)) {
166 0 : *index = dart_allocated_teamlist_array[imin].index;
167 : /* If search successfully, the position of the teamid in array is
168 : * returned.
169 : */
170 0 : return imin;
171 : } else {
172 0 : DART_LOG_ERROR("Invalid teamid input: %d", teamid);
173 0 : return -1;
174 : }
175 : }
|