Skip to content

Commit caac098

Browse files
committed
Move conneciton manager implementation to its own src file
1 parent cff362a commit caac098

File tree

3 files changed

+346
-346
lines changed

3 files changed

+346
-346
lines changed

codes/connection-manager.h

+1-346
Original file line numberDiff line numberDiff line change
@@ -220,351 +220,6 @@ class ConnectionManager {
220220
void print_connections();
221221
};
222222

223-
224-
//******************* BEGIN IMPLEMENTATION ********************************************************
225-
226-
//******************* Connection Manager Implementation *******************************************
227-
ConnectionManager::ConnectionManager(int src_id_local, int src_id_global, int src_group, int max_intra, int max_inter, int max_term, int num_router_per_group)
228-
{
229-
_source_id_local = src_id_local;
230-
_source_id_global = src_id_global;
231-
_source_group = src_group;
232-
233-
_used_intra_ports = 0;
234-
_used_inter_ports = 0;
235-
_used_terminal_ports = 0;
236-
237-
_max_intra_ports = max_intra;
238-
_max_inter_ports = max_inter;
239-
_max_terminal_ports = max_term;
240-
241-
_num_routers_per_group = num_router_per_group;
242-
}
243-
244-
void ConnectionManager::add_connection(int dest_gid, ConnectionType type)
245-
{
246-
Connection conn;
247-
conn.src_lid = _source_id_local;
248-
conn.src_gid = _source_id_global;
249-
conn.src_group_id = _source_group;
250-
conn.conn_type = type;
251-
conn.dest_lid = dest_gid % _num_routers_per_group;
252-
conn.dest_gid = dest_gid;
253-
conn.dest_group_id = dest_gid / _num_routers_per_group;
254-
255-
switch (type)
256-
{
257-
case CONN_LOCAL:
258-
if (intraGroupConnections.size() < _max_intra_ports) {
259-
conn.port = this->get_used_ports_for(CONN_LOCAL);
260-
intraGroupConnections[conn.dest_lid].push_back(conn);
261-
_used_intra_ports++;
262-
}
263-
else
264-
tw_error(TW_LOC,"Attempting to add too many local connections per router - exceeding configuration value: %d",_max_intra_ports);
265-
break;
266-
267-
case CONN_GLOBAL:
268-
if(globalConnections.size() < _max_inter_ports) {
269-
conn.port = _max_intra_ports + this->get_used_ports_for(CONN_GLOBAL);
270-
globalConnections[conn.dest_gid].push_back(conn);
271-
_used_inter_ports++;
272-
}
273-
else
274-
tw_error(TW_LOC,"Attempting to add too many global connections per router - exceeding configuration value: %d",_max_inter_ports);
275-
break;
276-
277-
case CONN_TERMINAL:
278-
if(terminalConnections.size() < _max_terminal_ports){
279-
conn.port = _max_intra_ports + _max_inter_ports + this->get_used_ports_for(CONN_TERMINAL);
280-
conn.dest_group_id = _source_group;
281-
terminalConnections[conn.dest_gid].push_back(conn);
282-
_used_terminal_ports++;
283-
}
284-
else
285-
tw_error(TW_LOC,"Attempting to add too many terminal connections per router - exceeding configuration value: %d",_max_terminal_ports);
286-
break;
287-
288-
default:
289-
assert(false);
290-
// TW_ERROR(TW_LOC, "add_connection(dest_id, type): Undefined connection type\n");
291-
}
292-
293-
if(conn.dest_group_id != conn.src_group_id)
294-
_other_groups_i_connect_to_set.insert(conn.dest_group_id);
295-
296-
_portMap[conn.port] = conn;
297-
}
298-
299-
// void ConnectionManager::add_route_to_group(Connection conn, int dest_group_id)
300-
// {
301-
// intermediateRouterToGroupMap[dest_group_id].push_back(conn);
302-
// }
303-
304-
// vector< Connection > ConnectionManager::get_intm_conns_to_group(int dest_group_id)
305-
// {
306-
// return intermediateRouterToGroupMap[dest_group_id];
307-
// }
308-
309-
// vector< int > ConnectionManager::get_intm_routers_to_group(int dest_group_id)
310-
// {
311-
// vector< Connection > intm_router_conns = get_intm_conns_to_group(dest_group_id);
312-
313-
// vector< int > loc_intm_router_ids;
314-
// vector< Connection >::iterator it;
315-
// for(it = intm_router_conns.begin(); it != intm_router_conns.end(); it++)
316-
// {
317-
// loc_intm_router_ids.push_back((*it).other_id);
318-
// }
319-
// return loc_intm_router_ids;
320-
// }
321-
322-
int ConnectionManager::get_source_id(ConnectionType type)
323-
{
324-
switch (type)
325-
{
326-
case CONN_LOCAL:
327-
return _source_id_local;
328-
case CONN_GLOBAL:
329-
return _source_id_global;
330-
default:
331-
assert(false);
332-
// TW_ERROR(TW_LOC, "get_source_id(type): Unsupported connection type\n");
333-
}
334-
}
335-
336-
vector<int> ConnectionManager::get_ports(int dest_id, ConnectionType type)
337-
{
338-
vector< Connection > conns = this->get_connections_to_gid(dest_id, type);
339-
340-
vector< int > ports_used;
341-
vector< Connection >::iterator it = conns.begin();
342-
for(; it != conns.end(); it++) {
343-
ports_used.push_back((*it).port); //add port from connection list to the used ports list
344-
}
345-
return ports_used;
346-
}
347-
348-
Connection ConnectionManager::get_connection_on_port(int port)
349-
{
350-
return _portMap[port];
351-
}
352-
353-
bool ConnectionManager::is_connected_to_by_type(int dest_id, ConnectionType type)
354-
{
355-
switch (type)
356-
{
357-
case CONN_LOCAL:
358-
if (intraGroupConnections.find(dest_id) != intraGroupConnections.end())
359-
return true;
360-
break;
361-
case CONN_GLOBAL:
362-
if (globalConnections.find(dest_id) != globalConnections.end())
363-
return true;
364-
break;
365-
case CONN_TERMINAL:
366-
if (terminalConnections.find(dest_id) != terminalConnections.end())
367-
return true;
368-
break;
369-
default:
370-
assert(false);
371-
// TW_ERROR(TW_LOC, "get_used_ports_for(type): Undefined connection type\n");
372-
}
373-
return false;
374-
}
375-
376-
bool ConnectionManager::is_any_connection_to(int dest_global_id)
377-
{
378-
int local_id = dest_global_id % _num_routers_per_group;
379-
if (intraGroupConnections.find(local_id) != intraGroupConnections.end())
380-
return true;
381-
if (globalConnections.find(dest_global_id) != globalConnections.end())
382-
return true;
383-
if (terminalConnections.find(dest_global_id) != terminalConnections.end())
384-
return true;
385-
386-
return false;
387-
}
388-
389-
int ConnectionManager::get_total_used_ports()
390-
{
391-
return _used_intra_ports + _used_inter_ports + _used_terminal_ports;
392-
}
393-
394-
int ConnectionManager::get_used_ports_for(ConnectionType type)
395-
{
396-
switch (type)
397-
{
398-
case CONN_LOCAL:
399-
return _used_intra_ports;
400-
case CONN_GLOBAL:
401-
return _used_inter_ports;
402-
case CONN_TERMINAL:
403-
return _used_terminal_ports;
404-
default:
405-
assert(false);
406-
// TW_ERROR(TW_LOC, "get_used_ports_for(type): Undefined connection type\n");
407-
}
408-
}
409-
410-
ConnectionType ConnectionManager::get_port_type(int port_num)
411-
{
412-
return _portMap[port_num].conn_type;
413-
}
414-
415-
416-
vector< Connection > ConnectionManager::get_connections_to_gid(int dest_gid, ConnectionType type)
417-
{
418-
switch (type)
419-
{
420-
case CONN_LOCAL:
421-
return intraGroupConnections[dest_gid%_num_routers_per_group];
422-
case CONN_GLOBAL:
423-
return globalConnections[dest_gid];
424-
case CONN_TERMINAL:
425-
return terminalConnections[dest_gid];
426-
default:
427-
assert(false);
428-
// TW_ERROR(TW_LOC, "get_connections(type): Undefined connection type\n");
429-
}
430-
}
431-
432-
vector< Connection > ConnectionManager::get_connections_to_group(int dest_group_id)
433-
{
434-
return _connections_to_groups_map[dest_group_id];
435-
}
436-
437-
vector< Connection > ConnectionManager::get_connections_by_type(ConnectionType type)
438-
{
439-
switch (type)
440-
{
441-
case CONN_LOCAL:
442-
return _all_conns_by_type_map[CONN_LOCAL];
443-
break;
444-
case CONN_GLOBAL:
445-
return _all_conns_by_type_map[CONN_GLOBAL];
446-
break;
447-
case CONN_TERMINAL:
448-
return _all_conns_by_type_map[CONN_TERMINAL];
449-
break;
450-
default:
451-
tw_error(TW_LOC, "Bad enum type\n");
452-
}
453-
}
454-
455-
vector< int > ConnectionManager::get_connected_group_ids()
456-
{
457-
return _other_groups_i_connect_to;
458-
}
459-
460-
void ConnectionManager::solidify_connections()
461-
{
462-
//-- other groups connect to
463-
set< int >::iterator it;
464-
for(it = _other_groups_i_connect_to_set.begin(); it != _other_groups_i_connect_to_set.end(); it++)
465-
{
466-
_other_groups_i_connect_to.push_back(*it);
467-
}
468-
469-
//--connections to group
470-
for(it = _other_groups_i_connect_to_set.begin(); it != _other_groups_i_connect_to_set.end(); it++)
471-
{
472-
int dest_group_id = *it;
473-
474-
vector< Connection > conns_to_group;
475-
map< int, vector< Connection > >::iterator itg = globalConnections.begin();
476-
for(; itg != globalConnections.end(); itg++) //iterate over each router that is connected to source
477-
{
478-
vector< Connection >::iterator conns_to_router;
479-
for(conns_to_router = (itg->second).begin(); conns_to_router != (itg->second).end(); conns_to_router++) //iterate over each connection to a specific router
480-
{
481-
if ((*conns_to_router).dest_group_id == dest_group_id) {
482-
conns_to_group.push_back(*conns_to_router);
483-
}
484-
}
485-
}
486-
487-
_connections_to_groups_map[dest_group_id] = conns_to_group;
488-
}
489-
490-
//--get connections by type
491-
492-
map< int, vector< Connection > > theMap;
493-
for ( int enum_int = CONN_LOCAL; enum_int != CONN_TERMINAL + 1; enum_int++ )
494-
{
495-
switch (enum_int)
496-
{
497-
case CONN_LOCAL:
498-
theMap = intraGroupConnections;
499-
break;
500-
case CONN_GLOBAL:
501-
theMap = globalConnections;
502-
break;
503-
case CONN_TERMINAL:
504-
theMap = terminalConnections;
505-
break;
506-
default:
507-
tw_error(TW_LOC, "Bad enum type\n");
508-
}
509-
510-
vector< Connection > retVec;
511-
map< int, vector< Connection > >::iterator it;
512-
for(it = theMap.begin(); it != theMap.end(); it++)
513-
{
514-
retVec.insert(retVec.end(), (*it).second.begin(), (*it).second.end());
515-
}
516-
_all_conns_by_type_map[enum_int] = retVec;
517-
}
518-
}
519-
520-
521-
void ConnectionManager::print_connections()
522-
{
523-
printf("Connections for Router: %d ---------------------------------------\n",_source_id_global);
524-
525-
int ports_printed = 0;
526-
map<int,Connection>::iterator it = _portMap.begin();
527-
for(; it != _portMap.end(); it++)
528-
{
529-
if ( (ports_printed == 0) && (_used_intra_ports > 0) )
530-
{
531-
printf(" -- Intra-Group Connections -- \n");
532-
printf(" Port | Dest_ID | Group\n");
533-
}
534-
if ( (ports_printed == _used_intra_ports) && (_used_inter_ports > 0) )
535-
{
536-
printf(" -- Inter-Group Connections -- \n");
537-
printf(" Port | Dest_ID | Group\n");
538-
}
539-
if ( (ports_printed == _used_intra_ports + _used_inter_ports) && (_used_terminal_ports > 0) )
540-
{
541-
printf(" -- Terminal Connections -- \n");
542-
printf(" Port | Dest_ID | Group\n");
543-
}
544-
545-
int port_num = it->first;
546-
int group_id = it->second.dest_group_id;
547-
548-
int id,gid;
549-
if( get_port_type(port_num) == CONN_LOCAL ) {
550-
id = it->second.dest_lid;
551-
gid = it->second.dest_gid;
552-
printf(" %d -> (%d,%d) : %d - LOCAL\n", port_num, id, gid, group_id);
553-
554-
}
555-
else if (get_port_type(port_num) == CONN_GLOBAL) {
556-
id = it->second.dest_gid;
557-
printf(" %d -> %d : %d - GLOBAL\n", port_num, id, group_id);
558-
}
559-
else if (get_port_type(port_num) == CONN_TERMINAL) {
560-
id = it->second.dest_gid;
561-
printf(" %d -> %d : %d - TERMINAL\n", port_num, id, group_id);
562-
}
563-
564-
ports_printed++;
565-
}
566-
}
567-
568-
223+
//implementation found in util/connection-manager.C
569224

570225
#endif /* end of include guard:*/

src/Makefile.subdir

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ src_libcodes_la_SOURCES = \
150150
src/util/jobmap-impl/jobmap-identity.c\
151151
src/util/codes-mapping-context.c \
152152
src/util/codes-comm.c \
153+
src/util/connection-manager.C \
153154
src/workload/codes-workload.c \
154155
src/workload/methods/codes-iolang-wrkld.c \
155156
src/workload/methods/codes-checkpoint-wrkld.c \

0 commit comments

Comments
 (0)