def saveWorkflow(f, mods, numSlaves, remote): f.write("\n") for m in mods: hub = _vistle.getHub(m) if (remote and hub==getMasterHub()) or (not remote and hub!=getMasterHub()): continue #f.write(modvar(m)+" = spawn('"+_vistle.getModuleName(m)+"')\n") f.write("u"+modvar(m)+" = spawnAsync("+hubVarForModule(m, numSlaves)+", '"+_vistle.getModuleName(m)+"')\n") for m in mods: hub = _vistle.getHub(m) if (remote and hub==getMasterHub()) or (not remote and hub!=getMasterHub()): continue f.write(modvar(m)+" = waitForSpawn(u"+modvar(m)+")\n") saveParameters(f, m) for m in mods: hub = _vistle.getHub(m) if (not remote and hub!=getMasterHub()): continue ports = getOutputPorts(m) for p in ports: conns = getConnections(m, p) for c in conns: hub2 = _vistle.getHub(c[0]) if (remote and hub==getMasterHub() and hub2==getMasterHub()) or (not remote and (hub!=getMasterHub() or hub2!=getMasterHub())): continue f.write("connect("+modvar(m)+",'"+str(p)+"', "+modvar(c[0])+",'"+str(c[1])+"')\n")
def showRunning(): running = _vistle.getRunning() print("id\tname\thub") for id in running: name = _vistle.getModuleName(id) hub = _vistle.getHub(id) print("%s\t%s\t%s" % (id, name, hub))
def save(filename=None): global _loaded_file if filename == None: filename = _loaded_file if filename == None: print("No file loaded and no file specified") return f = open(filename, 'w') mods = _vistle.getRunning() master = getMasterHub() f.write("MasterHub=" + str(master) + "\n") slavehubs = set() for m in mods: h = _vistle.getHub(m) if h != master: slavehubs.add(h) numSlaves = len(slavehubs) if numSlaves > 1: print("slave hubs: %s" % slavehubs) f.write("waitForSlaves()\n") f.write("waitForHub()\n") elif numSlaves > 0: print("slave hubs: %s" % slavehubs) f.write("print('waiting for a slave hub to connect...')\n") f.write("printInfo('waiting for a slave hub to connect...')\n") f.write("SlaveHub=waitForHub()\n") f.write("print('slave hub %s connected\\n' % SlaveHub)\n") f.write("printInfo('slave hub %s connected\\n' % SlaveHub)\n") f.write("uuids = {}\n") for m in mods: #f.write(modvar(m)+" = spawn('"+_vistle.getModuleName(m)+"')\n") f.write("u" + modvar(m) + " = spawnAsync(" + hubvar(m, numSlaves) + ", '" + _vistle.getModuleName(m) + "')\n") for m in mods: f.write(modvar(m) + " = waitForSpawn(u" + modvar(m) + ")\n") params = getParameters(m) for p in params: if not isParameterDefault(m, p): f.write("set" + getParameterType(m, p) + "Param(" + modvar(m) + ", '" + p + "', " + str(getSavableParam(m, p)) + ")\n") f.write("\n") for m in mods: ports = getOutputPorts(m) for p in ports: conns = getConnections(m, p) for c in conns: f.write("connect(" + modvar(m) + ",'" + str(p) + "', " + modvar(c.first) + ",'" + str(c.second) + "')\n") #f.write("checkMessageQueue()\n") f.close() print("Data flow network saved to " + filename)
def showAllParameters(): mods = _vistle.getRunning() print("id\tmodule\tname\ttype\tvalue") for m in mods: name = _vistle.getModuleName(m) params = getParameters(m) for p in params: print("%s\t%s\t%s\t%s\t%s" % (m, name, p, getParameterType(m, p), getSavableParam(m, p)))
def saveWorkflow(f, mods, numSlaves, remote): f.write("\n") if remote: f.write("# spawn all remote modules\n") else: f.write("# spawn all local modules\n") for m in mods: hub = _vistle.getHub(m) if (remote and hub == _vistle.getMasterHub()) or ( not remote and hub != _vistle.getMasterHub()): continue #f.write(modvar(m)+" = spawn('"+_vistle.getModuleName(m)+"')\n") f.write("u" + modvar(m) + " = spawnAsync(" + hubVarForModule(m, numSlaves) + ", '" + _vistle.getModuleName(m) + "')\n") f.write("\n") for m in mods: hub = _vistle.getHub(m) if (remote and hub == _vistle.getMasterHub()) or ( not remote and hub != _vistle.getMasterHub()): continue f.write(modvar(m) + " = waitForSpawn(u" + modvar(m) + ")\n") saveParameters(f, m) if remote: f.write("# connections between local and remote\n") else: f.write("# all local connections\n") writtenConns = [] for m in mods: hub = _vistle.getHub(m) if (not remote and hub != _vistle.getMasterHub()): continue ports = _vistle.getOutputPorts(m) params = _vistle.getParameters(m) all = ports + params for p in all: conns = _vistle.getConnections(m, p) for c in conns: hub2 = _vistle.getHub(c[0]) if (remote and hub == _vistle.getMasterHub() and hub2 == _vistle.getMasterHub()) or ( not remote and (hub != _vistle.getMasterHub() or hub2 != _vistle.getMasterHub())): continue if [str(m), p] in writtenConns: continue else: f.write("connect(" + modvar(m) + ",'" + str(p) + "', " + modvar(c[0]) + ",'" + str(c[1]) + "')\n") writtenConns.append([str(c[0]), c[1]])
def save(filename = None): global _loaded_file if filename == None: filename = _loaded_file if filename == None: print("No file loaded and no file specified") return f = open(filename, 'w') mods = _vistle.getRunning() master = getMasterHub() f.write("MasterHub="+str(master)+"\n") slavehubs = set() for m in mods: h = _vistle.getHub(m) if h != master: slavehubs.add(h) numSlaves = len(slavehubs) if numSlaves > 1: print("slave hubs: %s" % slavehubs) f.write("waitForSlaves()\n") f.write("waitForHub()\n") elif numSlaves > 0: print("slave hubs: %s" % slavehubs) f.write("print('waiting for a slave hub to connect...')\n") f.write("SlaveHub=waitForHub()\n") f.write("print('slave hub %s connected\\n' % SlaveHub)\n") f.write("uuids = {}\n"); for m in mods: #f.write(modvar(m)+" = spawn('"+_vistle.getModuleName(m)+"')\n") f.write("u"+modvar(m)+" = spawnAsync("+hubvar(m, numSlaves)+", '"+_vistle.getModuleName(m)+"')\n") for m in mods: f.write(modvar(m)+" = waitForSpawn(u"+modvar(m)+")\n") params = getParameters(m) for p in params: if not isParameterDefault(m, p): f.write("set"+getParameterType(m,p)+"Param("+modvar(m)+", '"+p+"', "+str(getSavableParam(m,p))+")\n") f.write("\n") for m in mods: ports = getOutputPorts(m) for p in ports: conns = getConnections(m, p) for c in conns: f.write("connect("+modvar(m)+",'"+str(p)+"', "+modvar(c.first)+",'"+str(c.second)+"')\n") #f.write("checkMessageQueue()\n") f.close() print("Data flow network saved to "+filename)
def showBusy(): busy = getBusy() print("id\tname") for id in busy: name = _vistle.getModuleName(id) print("%s\t%s" % (id, name))
def modvar(id): if (id >= 0): return "m" + _vistle.getModuleName(id) + str(id) if (id == _vistle.getVistleSession()): return "VistleSession" return "v" + str(-id)
def modvar(id): if (id >= 0): return "m" + _vistle.getModuleName(id) + str(id) if (id == _vistle.getVistleSession()): return "VistleSession" return "v"+str(-id)
def modvar(id): return "m" + _vistle.getModuleName(id) + str(id)