+
+# now computes joining lines between segments
+joinseg=[]
+
+print("\n/**\n *------------------ <copy/paste C code snippet in surf/network.c> ----------------------")
+print(" *\n * produced by: {0}\n *".format(' '.join(sys.argv)))
+print(" *---------------------------------------------------------------------------------------\n **/")
+
+# print correction factor for bandwidth for each segment
+print("static double smpi_bandwidth_factor(double size)\n{")
+for (lb,ub,a,b,factor_bw,factor_lat) in factors:
+ c_code_print(lb,ub,factor_bw,True,True)
+
+ # save ends and starts of segments
+ if lb != sizes[0]:
+ joinseg.append( (lb,timings[sizes.index(lb)]) )
+ if ub != sizes[-1]:
+ joinseg.append( (ub,timings[sizes.index(ub)]) )
+
+# print correction factor for bandwidth between segments
+joinseg.reverse()
+print("\n\t /* ..:: inter-segment corrections ::.. */");
+inx=len(joinseg)-1
+while inx>=1:
+ (x0,y0) = joinseg[inx]
+ inx = inx -1
+ (x1,y1) = joinseg[inx]
+ inx = inx -1
+ # line eq. is y = (y1-y0)/(x0-x1) * x + (y0 x1 - y1 x0)/(x1-x0)
+ a = (y1-y0) / (x1-x0)
+ bw_join = 1e6 / a
+ factor_join_bw = bw_join / bandwidth
+ #print("Joining points (%f,%f) -> (%f,%f) : line dir : a=%g\n" % (x0,y0,x1,y1,a))
+ c_code_print(x0,x1,factor_join_bw,False,False)
+
+print("}\n")
+
+# print correction factor for latency for each segment
+print("static double smpi_latency_factor(double size)\n{")
+for (lb,ub,a,b,factor_bw,factor_lat) in factors:
+ c_code_print(lb,ub,factor_lat,True,True)
+
+print("\n\t /* ..:: inter-segment corrections ::.. */");
+while joinseg:
+ (x0,y0) = joinseg.pop()
+ (x1,y1) = joinseg.pop()
+ # line eq. is y = (y0-y1)/(x0-x1) * x + (y0 x1 - y1 x0)/(x1-x0)
+ #print("(%f,%f) -> (%f,%f)\n" % (x0,y0,x1,y1))
+ b = 1e-6 * (y0*x1-y1*x0) / (x1-x0)
+ factor_join_lat = b / (latency*links)
+ c_code_print(x0,x1,factor_join_lat,False,False)
+
+print("}\n")
+
+print("\n/**\n *------------------ <copy/paste C code snippet in surf/network.c> ----------------------\n **/")