1 /* Copyright (c) 2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "network_ib.hpp"
8 #include "simgrid/sg_config.h"
9 #include "maxmin_private.hpp"
11 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
18 static void IB_create_host_callback(sg_platf_host_cbarg_t t){
21 // pour t->id -> rajouter une nouvelle struct dans le dict, pour stocker les comms actives
22 if(((NetworkIBModel*)surf_network_model)->active_nodes==NULL)
23 ((NetworkIBModel*)surf_network_model)->active_nodes=xbt_dict_new();
25 IBNode* act = new IBNode(id);
28 xbt_dict_set(((NetworkIBModel*)surf_network_model)->active_nodes, t->id, act, NULL);
32 static void IB_action_state_changed_callback(NetworkActionPtr action, e_surf_action_state_t statein, e_surf_action_state_t stateout){
33 if(statein!=SURF_ACTION_RUNNING|| stateout!=SURF_ACTION_DONE)
35 std::pair<IBNode*,IBNode*> pair = ((NetworkIBModel*)surf_network_model)->active_comms[action];
36 XBT_VERB("action %p finished", action);
38 ((NetworkIBModel*)surf_network_model)->updateIBfactors(action, pair.first, pair.second, 1);
40 ((NetworkIBModel*)surf_network_model)->active_comms.erase(action);
45 static void IB_action_init_callback(NetworkActionPtr action,RoutingEdgePtr src, RoutingEdgePtr dst, double size, double rate){
46 if(((NetworkIBModel*)surf_network_model)->active_nodes==NULL)
47 xbt_die("IB comm added, without any node connected !");
49 IBNode* act_src= (IBNode*) xbt_dict_get_or_null(((NetworkIBModel*)surf_network_model)->active_nodes, src->getName());
51 xbt_die("could not find src node active comms !");
54 IBNode* act_dst= (IBNode*) xbt_dict_get_or_null(((NetworkIBModel*)surf_network_model)->active_nodes, dst->getName());
56 xbt_die("could not find dst node active comms !");
57 // act_dst->rate=rate;
59 ((NetworkIBModel*)surf_network_model)->active_comms[action]=make_pair<IBNode*,IBNode*>(act_src, act_dst);
60 //post the action in the second dist, to retrieve in the other callback
61 XBT_VERB("action %p init", action);
63 ((NetworkIBModel*)surf_network_model)->updateIBfactors(action, act_src, act_dst, 0);
73 /************************************************************************/
74 /* New model based on MPI contention model for Infiniband platforms */
75 /************************************************************************/
76 /* @Inproceedings{mescal_vienne_phd, */
77 /* author={Jérôme Vienne}, */
78 /* title={prédiction de performances d’applications de calcul haute performance sur réseau Infiniband}, */
79 /* address={Grenoble FRANCE}, */
83 void surf_network_model_init_IB(void)
86 if (surf_network_model)
88 surf_network_model = new NetworkIBModel();
89 net_define_callbacks();
90 xbt_dynar_push(model_list, &surf_network_model);
91 surf_callback_connect(networkActionStateChangedCallbacks, IB_action_state_changed_callback);
92 surf_callback_connect(networkCommunicateCallbacks, IB_action_init_callback);
94 sg_platf_host_add_cb(IB_create_host_callback);
95 xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775);
98 NetworkIBModel::NetworkIBModel()
99 : NetworkSmpiModel() {
104 NetworkIBModel::~NetworkIBModel()
106 xbt_dict_cursor_t cursor = NULL;
107 IBNode* instance = NULL;
109 xbt_dict_foreach(active_nodes, cursor, name, instance)
111 xbt_dict_free(&active_nodes);
114 void NetworkIBModel::computeIBfactors(IBNode *root) {
115 double penalized_bw=0.0;
116 double num_comm_out = (double) root->ActiveCommsUp.size();
117 double max_penalty_out=0.0;
118 //first, compute all outbound penalties to get their max
119 for (std::vector<ActiveComm*>::iterator it= root->ActiveCommsUp.begin(); it != root->ActiveCommsUp.end(); ++it) {
120 double my_penalty_out = 1.0;
123 if((*it)->destination->nbActiveCommsDown > 2)//number of comms sent to the receiving node
124 my_penalty_out = num_comm_out * Bs * ys;
126 my_penalty_out = num_comm_out * Bs;
129 max_penalty_out = max(max_penalty_out,my_penalty_out);
132 for (std::vector<ActiveComm*>::iterator it= root->ActiveCommsUp.begin(); it != root->ActiveCommsUp.end(); ++it) {
134 //compute inbound penalty
135 double my_penalty_in = 1.0;
136 int nb_comms = (*it)->destination->nbActiveCommsDown;//total number of incoming comms
138 my_penalty_in = ((*it)->destination->ActiveCommsDown)[root] //number of comm sent to dest by root node
140 * (*it)->destination->ActiveCommsDown.size();//number of different nodes sending to dest
142 double penalty=max(my_penalty_in,max_penalty_out);
144 double rate_before_update = (*it)->action->getBound();
145 //save initial rate of the action
146 if((*it)->init_rate==-1)
147 (*it)->init_rate= rate_before_update;
149 penalized_bw= ! num_comm_out ? (*it)->init_rate : (*it)->init_rate /penalty;
151 if (!double_equals(penalized_bw, rate_before_update, sg_surf_precision)){
152 // XBT_VERB("%d->%d action %p penalty updated : in %f, out %f, final %f, before %f , initial rate %f", root->id,(*it)->destination->id,(*it)->action,my_penalty_in,my_penalty_out,penalized_bw, (*it)->action->getBound(), (*it)->init_rate );
153 lmm_update_variable_bound(p_maxminSystem, (*it)->action->getVariable(), penalized_bw);
155 // XBT_VERB("%d->%d action %p penalty not updated : in %f, out %f, final %f, initial rate %f", root->id,(*it)->destination->id,(*it)->action,my_penalty_in,my_penalty_out,penalized_bw, (*it)->init_rate );
159 XBT_VERB("Finished computing");
162 void NetworkIBModel::updateIBfactors_rec(IBNode *root, bool* updatedlist) {
163 if(updatedlist[root->id]==0){
164 XBT_VERB("Updating rec %d", root->id);
165 computeIBfactors(root);
166 updatedlist[root->id]=1;
167 for (std::vector<ActiveComm*>::iterator it= root->ActiveCommsUp.begin(); it != root->ActiveCommsUp.end(); ++it) {
168 if(updatedlist[(*it)->destination->id]!=1)
169 updateIBfactors_rec((*it)->destination, updatedlist);
171 for (std::map<IBNode*, int>::iterator it= root->ActiveCommsDown.begin(); it != root->ActiveCommsDown.end(); ++it) {
172 if(updatedlist[it->first->id]!=1)
173 updateIBfactors_rec(it->first, updatedlist);
179 void NetworkIBModel::updateIBfactors(NetworkActionPtr action, IBNode *from, IBNode * to, int remove) {
180 if (from == to)//disregard local comms (should use loopback)
183 bool* updated=(bool*)xbt_malloc0(xbt_dict_size(active_nodes)*sizeof(bool));
184 ActiveComm* comm=NULL;
186 if(to->ActiveCommsDown[from]==1)
187 to->ActiveCommsDown.erase(from);
189 to->ActiveCommsDown[from]-=1;
191 to->nbActiveCommsDown--;
192 for (std::vector<ActiveComm*>::iterator it= from->ActiveCommsUp.begin();
193 it != from->ActiveCommsUp.end(); ++it) {
194 XBT_VERB("inside vector");
195 if((*it)->action==action){
197 from->ActiveCommsUp.erase(it);
198 XBT_VERB("action deleted");
203 /*from->ActiveCommsUp.erase(
204 std::remove(from->ActiveCommsUp.begin(),
205 from->ActiveCommsUp.end(), make_pair(to, action)),
206 from->ActiveCommsUp.end());*/
209 //from->ActiveCommsUp.push_back(std::make_pair(to, action));
212 ActiveComm* comm=new ActiveComm();
214 comm->destination=to;
215 from->ActiveCommsUp.push_back(comm);
217 to->ActiveCommsDown[from]+=1;
218 to->nbActiveCommsDown++;
220 XBT_VERB("Updating %d", from->id);
221 updateIBfactors_rec(from, updated);
222 XBT_VERB("Finished updating %d", from->id);