I'm trying to get a list of nodes like APSP (all pairs short path) and want to use rapids cugraph for GPU acceleration. Researched a bit and created this script which is working but it's very slow. I suppose I'm doing the wrong iteration and there could be a better way to achieve the same result faster. Am I on the wrong way? Thank you!
import sqlalchemy
import cugraph
import cudf
import pandas as pd
from datetime import datetime
s_time = datetime.now()
engine = sqlalchemy.create_engine('postgresql://postgres:xxxxxxx@localhost:5432/postgres')
sql = "select id, source, target, cost, geom from xxx.roads_noded"
rc = "select source, target from xxx.routin_candidates"
df = pd.read_sql(sql, engine)
rcdf = pd.read_sql(rc, engine)
cuda_g = cudf.DataFrame.from_pandas(df)
cuda_nc = cudf.DataFrame.from_pandas(rcdf)
G = cugraph.Graph()
G.from_cudf_edgelist(cuda_g, source='source', destination='target', edge_attr='cost')
for index, row in cuda_nc.to_pandas().iterrows():
src = row['source']
dest = row['target']
routes = cugraph.sssp(G, src)
for index, row in routes.to_pandas().iterrows():
v = int(row['vertex'])
if v == dest:
p = cugraph.utils.get_traversed_path_list(routes, v)
autoroute = p[::-1]
print(autoroute)
e_time = datetime.now()
print('Duration: {}'.format(e_time - s_time))