def create_edges(self, nx_edges, client, client_id, node_map): with self.lock: while not self.startThread: self.cv.wait() cntr = 0 edges = {} for edge in nx_edges: if cntr % TX_SIZE == 0: client.begin_tx() self.edge_handles[node_map[edge[0]]].append(client.create_edge(node_map[edge[0]], node_map[edge[1]])) if node_map[edge[0]] not in edges: edges[node_map[edge[0]]] = [] edges[node_map[edge[0]]].append(node_map[edge[1]]) if cntr % TX_SIZE == (TX_SIZE-1) or TX_SIZE == 1 or cntr == (len(nx_edges)-1): client.end_tx() if cntr % 1000 == 0: print 'Client ' + str(client_id) + ' created ' + str(cntr) + ' edges' cntr += 1 with self.lock: for n in edges: self.edges[n].extend(edges[n])
def create_nodes(self, nx_nodes, client, client_id, nodes_per_thread): with self.lock: while not self.startThread: self.cv.wait() cntr = 0 w_nodes = [] for node in nx_nodes: if cntr % TX_SIZE == 0: client.begin_tx() wnode = client.create_node() w_nodes.append(wnode) if cntr % TX_SIZE == (TX_SIZE-1) or TX_SIZE == 1 or cntr == (len(nx_nodes)-1): client.end_tx() if cntr % 1000 == 0: print 'Client ' + str(client_id) + ' created ' + str(cntr) + ' nodes' cntr += 1 with self.lock: for i in range(len(nx_nodes)): self.nodes[i+client_id*nodes_per_thread] = w_nodes[i] self.node_map[nx_nodes[i]] = w_nodes[i] self.edges[w_nodes[i]] = [] self.edge_handles[w_nodes[i]] = []