repo_id
stringlengths 21
96
| file_path
stringlengths 31
155
| content
stringlengths 1
92.9M
| __index_level_0__
int64 0
0
|
---|---|---|---|
rapidsai_public_repos/nvgraph | rapidsai_public_repos/nvgraph/test/log_converter.py | #!/usr/bin/python
from sys import argv
from subprocess import Popen, PIPE, STDOUT
from os import path, environ
def main():
args = argv[1:]
args[0] = path.join('./', args[0])
print args
environ["GTEST_PRINT_TIME"] = "0"
popen = Popen(args, stdout=PIPE, stderr=STDOUT)
stillParsing = True
skip = []
while not popen.poll():
data = popen.stdout.readline().splitlines()
if len(data) == 0:
break
data = data[0]
try:
STATUS = data[0:12]
NAME = data[12:]
if data.find('Global test environment tear-down') != -1:
stillParsing = False
if stillParsing:
if STATUS == "[ RUN ]":
print('&&&& RUNNING' + NAME)
elif STATUS == "[ OK ]" and NAME.strip() not in skip:
print('&&&& PASSED ' + NAME)
elif STATUS == "[ WAIVED ]":
print('&&&& WAIVED ' + NAME)
skip.append(NAME.strip())
elif STATUS == "[ FAILED ]":
NAME = NAME.replace(', where', '\n where')
print('&&&& FAILED ' + NAME)
else:
print(data)
else:
print(data)
except IndexError:
print(data)
return popen.returncode
if __name__ == '__main__':
main()
| 0 |
rapidsai_public_repos/nvgraph | rapidsai_public_repos/nvgraph/test/data_gen.sh | #!/bin/sh
#Usage sh data_gen size1 size2 ...
#Generate power law in-degree plus rmat graphs of size size1 ... sizeN
#Corresponding transposed and binary csr are generated as well
convert (){
edges=$1
#echo "Starting Sort on $edges..."
./generators/convertors/sort $edges
#echo "Done"
tmp="_s"
sedges=$edges$tmp
echo "Starting H on $sedges ..."
./generators/convertors/H $sedges
#echo "Done"
tmp="_mtx"
matrix=$sedges$tmp
#delete soted edges
rm $sedges
echo "Starting HTa on $matrix ..."
./generators/convertors/HTA $matrix
tmp="_T"
outp=$edges$tmp
outpp=$matrix$tmp
mv $outpp $outp
#delete H
rm $matrix
#echo "Starting binary conversion ..."
./generators/convertors/mtob $outp
#echo "Generated transposed coo and transposed csr bin"
}
echo "Building the tools ..."
make -C generators
make -C generators/convertors
#generate the graphs we need here
#loop over script arguments which represent graph sizes.
for var in "$@"
do
echo "Generate graphs of size $var"
vertices=$var
option="i"
./generators/plodg $vertices $option
./generators/rmatg $vertices $option
graph="plod_graph_"
format=".mtx"
path_to_data="local_test_data/"
name="$path_to_data$graph$vertices$format"
convert $name
graph="rmat_graph_"
name="$path_to_data$graph$vertices$format"
convert $name
done
| 0 |
rapidsai_public_repos/nvgraph | rapidsai_public_repos/nvgraph/test/run_all_tests.sh | #!/bin/sh
#Usage sh run_all_tests.sh
#Run all the tests in the current directory (ie. you should copy it in your build/test/ directory).
test="nvgraph_test
csrmv_test
semiring_maxmin_test
semiring_minplus_test
semiring_orand_test
pagerank_test
sssp_test
max_flow_test"
for i in $test
do
./$i
done
| 0 |
rapidsai_public_repos/nvgraph/test | rapidsai_public_repos/nvgraph/test/ref/cpu_ref_pagerank.py | #!/usr/bin/python
# Usage : python3 nvgraph_cpu_ref.py graph.mtx alpha
# This will convert matrix values to default probabilities
# This will also write same matrix in CSC format and with dangling notes
#import numpy as np
import sys
import time
from scipy.io import mmread
import numpy as np
#import matplotlib.pyplot as plt
import networkx as nx
import os
#from test_pagerank import pagerank
print ('Networkx version : {} '.format(nx.__version__))
# Command line arguments
argc = len(sys.argv)
if argc<=2:
print("Error: usage is : python3 cpu_ref_pagerank.py graph.mtx alpha")
sys.exit()
mmFile = sys.argv[1]
alpha = float(sys.argv[2])
print('Reading '+ str(mmFile) + '...')
#Read
M = mmread(mmFile).asfptype()
nnz_per_row = {r : 0 for r in range(M.get_shape()[0])}
for nnz in range(M.getnnz()):
nnz_per_row[M.row[nnz]] = 1 + nnz_per_row[M.row[nnz]]
for nnz in range(M.getnnz()):
M.data[nnz] = 1.0/float(nnz_per_row[M.row[nnz]])
MT = M.transpose(True)
M = M.tocsr()
if M is None :
raise TypeError('Could not read the input graph')
if M.shape[0] != M.shape[1]:
raise TypeError('Shape is not square')
# should be autosorted, but check just to make sure
if not M.has_sorted_indices:
print('sort_indices ... ')
M.sort_indices()
n = M.shape[0]
dangling = [0]*n
for row in range(n):
if M.indptr[row] == M.indptr[row+1]:
dangling[row] = 1
else:
pass #M.data[M.indptr[row]:M.indptr[row+1]] = [1.0/float(M.indptr[row+1] - M.indptr[row])]*(M.indptr[row+1] - M.indptr[row])
#MT.data = M.data
# in NVGRAPH tests we read as CSR and feed as CSC, so here we doing this explicitly
print('Format conversion ... ')
# Directed NetworkX graph
print (M.shape[0])
Gnx = nx.DiGraph(M)
z = {k: 1.0/M.shape[0] for k in range(M.shape[0])}
#SSSP
print('Solving... ')
t1 = time.time()
pr = nx.pagerank(Gnx, alpha=alpha, nstart = z, max_iter=5000, tol = 1e-10) #same parameters as in NVGRAPH
t2 = time.time() - t1
print('Time : '+str(t2))
print('Writing result ... ')
'''
#raw rank results
# fill missing with DBL_MAX
bres = np.zeros(M.shape[0], dtype=np.float64)
for r in pr.keys():
bres[r] = pr[r]
print len(pr.keys())
# write binary
out_fname = '/tmp/' + os.path.splitext(os.path.basename(mmFile))[0] + '_T.pagerank_' + str(alpha) + '.bin'
bres.tofile(out_fname, "")
print 'Result is in the file: ' + out_fname
'''
#Indexes
sorted_pr = [item[0] for item in sorted(pr.items(), key=lambda x: x[1])]
bres = np.array(sorted_pr, dtype = np.int32)
#print (bres)
out_fname = os.path.splitext(os.path.basename(mmFile))[0] + '_T.pagerank_idx_' + str(alpha) + '.bin'
bres.tofile(out_fname, "")
print ('Vertices index sorted by pageranks in file: ' + out_fname)
#Values
out_fname = os.path.splitext(os.path.basename(mmFile))[0] + '_T.pagerank_val_' + str(alpha) + '.bin'
#print (np.array(sorted(pr.values()), dtype = np.float64))
np.array(sorted(pr.values()), dtype = np.float64).tofile(out_fname, "")
print ('Pagerank sorted values in file: ' + out_fname)
print ('Converting and Writing CSC')
b = open(os.path.splitext(os.path.basename(mmFile))[0] + '_T.mtx', "w")
b.write("%%MatrixMarket matrix coordinate real general\n")
b.write("%%NVAMG rhs\n")
b.write("{} {} {}\n".format(n, n, M.getnnz()))
for item in range(MT.getnnz()):
b.write("{} {} {}\n".format(MT.row[item] + 1, MT.col[item] + 1, MT.data[item]))
for val in dangling:
b.write(str(val) + "\n")
b.close()
print ("Wrote CSC to the file: "+ os.path.splitext(os.path.basename(mmFile))[0] + '_T.mtx')
print('Done')
| 0 |
rapidsai_public_repos/nvgraph/test | rapidsai_public_repos/nvgraph/test/ref/ref_sssp_BGL.cpp | #include <boost/config.hpp>
#include <iostream>
#include <fstream> //file output
#include <cfloat>
#include <omp.h>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/property_map/property_map.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/rmat_graph_generator.hpp>
#include <boost/random/linear_congruential.hpp>
#include <boost/graph/graph_traits.hpp>
void printUsageAndExit()
{
printf("%s", "Usage:./rmatg x y\n");
printf("%s", "x is the size of the graph, x>32 (Boost generator hang if x<32)\n");
printf("%s", "y is the source of sssp\n");
exit(0);
}
int main(int argc, char *argv[])
{
// read size
if (argc < 3) printUsageAndExit();
int size = atoi (argv[1]);
if (size<32) printUsageAndExit();
int source_sssp =atoi (argv[2]);
assert (size > 1 && size < INT_MAX);
assert (source_sssp >= 0 && source_sssp < size);
const unsigned num_edges = 15 * size;
// Some boost types
typedef boost::no_property VertexProperty;
typedef boost::property<boost::edge_weight_t, float> EdgeProperty;
typedef boost::adjacency_list<boost::mapS, boost::vecS, boost::directedS, VertexProperty, EdgeProperty> Graph;
typedef boost::unique_rmat_iterator<boost::minstd_rand, Graph> RMATGen;
typedef boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor;
boost::minstd_rand gen;
boost::graph_traits<Graph>::edge_iterator edge, edge_end;
/************************
* Random weights
************************/
// !!! WARNING !!!
// watch the stack
float* weight = new float[num_edges];
int count = 0;
for( int i = 0; i < num_edges; ++i)
weight[i] = (rand()%10)+(rand()%100)*(1.2e-2f);
/************************
* RMAT Gen
************************/
Graph g(RMATGen(gen, size, num_edges, 0.57, 0.19, 0.19, 0.05,true),RMATGen(),weight, size);
std::cout << "Generator : done. Edges = "<<boost::num_edges(g)<<std::endl;
assert (num_edges == boost::num_edges(g));
// debug print after gen
//for( boost::tie(edge, edge_end) = boost::edges(g); edge != edge_end; ++edge)
// std::cout << boost::source(*edge, g) << ' ' << boost::target(*edge, g)<< ' '<< boost::get(boost::get(boost::edge_weight, g),*edge) << '\n';
/************************
* Dijkstra
************************/
std::vector<vertex_descriptor> p(num_vertices(g));
std::vector<float> d(num_vertices(g));
vertex_descriptor s = vertex(source_sssp, g); //define soruce node
double start = omp_get_wtime();
dijkstra_shortest_paths(g, s,
predecessor_map(boost::make_iterator_property_map(p.begin(), get(boost::vertex_index, g))).
distance_map(boost::make_iterator_property_map(d.begin(), get(boost::vertex_index, g))));
double stop = omp_get_wtime();
std::cout << "Time = " << stop-start << "s"<< std::endl;
/************************
* Print
************************/
/*
boost::graph_traits<Graph>::vertex_iterator vi, vend;
std::cout << "SOURCE = "<< source_sssp << std::endl;
for (boost::tie(vi, vend) = vertices(g); vi != vend; ++vi)
{
if (d[*vi] != FLT_MAX)
{
std::cout << "d(" << *vi << ") = " << d[*vi] << ", ";
std::cout << "parent = " << p[*vi] << std::endl;
}
else
std::cout << "d(" << *vi << ") = INF"<< std::endl;
}
*/
return 0;
}
| 0 |
rapidsai_public_repos/nvgraph/test | rapidsai_public_repos/nvgraph/test/ref/cpu_ref_SSSP.py | #!/usr/bin/python
# Usage : python3 nvgraph_cpu_ref.py graph.mtx source_vertex
# This works with networkx 1.8.1 (default ubuntu package version in 14.04)
# http://networkx.github.io/documentation/networkx-1.8/
# Latest version is currenlty 1.11 in feb 2016
# https://networkx.github.io/documentation/latest/tutorial/index.html
#import numpy as np
import sys
import time
from scipy.io import mmread
import numpy as np
import networkx as nx
import os
print ('Networkx version : {} '.format(nx.__version__))
# Command line arguments
argc = len(sys.argv)
if argc<=2:
print("Error: usage is : python3 nvgraph_cpu_ref.py graph.mtx source_vertex")
sys.exit()
mmFile = sys.argv[1]
src = int(sys.argv[2])
print('Reading '+ str(mmFile) + '...')
#Read
M = mmread(mmFile).asfptype().tolil()
if M is None :
raise TypeError('Could not read the input graph')
# in NVGRAPH tests we read as CSR and feed as CSC, so here we doing this explicitly
M = M.transpose().tocsr()
if not M.has_sorted_indices:
M.sort_indices()
# Directed NetworkX graph
Gnx = nx.DiGraph(M)
#SSSP
print('Solving... ')
t1 = time.time()
sssp = nx.single_source_dijkstra_path_length(Gnx,source=src)
t2 = time.time() - t1
print('Time : '+str(t2))
print('Writing result ... ')
# fill missing with DBL_MAX
bsssp = np.full(M.shape[0], sys.float_info.max, dtype=np.float64)
for r in sssp.keys():
bsssp[r] = sssp[r]
# write binary
out_fname = os.path.splitext(os.path.basename(mmFile))[0] + '_T.sssp_' + str(src) + '.bin'
bsssp.tofile(out_fname, "")
print ('Result is in the file: ' + out_fname)
# write text
#f = open('/tmp/ref_' + os.path.basename(mmFile) + '_sssp.txt', 'w')
#f.write(str(sssp.values()))
print('Done')
| 0 |
rapidsai_public_repos/nvgraph/test | rapidsai_public_repos/nvgraph/test/ref/cpu_ref_widest.py | #!/usr/bin/python
# Generates widest path vector for the single source vertex to all other vertices using dijkstra-like algorithm
# Usage : python3 nvgraph_cpu_ref.py graph.mtx source_vertex
# This works with networkx 1.8.1 (default ubuntu package version in 14.04)
# http://networkx.github.io/documentation/networkx-1.8/
# Latest version is currenlty 1.11 in feb 2016
# https://networkx.github.io/documentation/latest/tutorial/index.html
#import numpy as np
import sys
import time
from scipy.io import mmread
import numpy as np
import matplotlib.pyplot as plt
import networkx as nx
import os
import sys
#modified widest
def _dijkstra_custom(G, source, get_weight, cutoff=None):
G_succ = G.succ if G.is_directed() else G.adj
width = {node: -sys.float_info.max for node in range(G.number_of_nodes())} # dictionary of final distances
width[source] = sys.float_info.max
#seen = set()
Qset = set([(source, 0)])
while len(Qset) > 0:
u, depth = Qset.pop()
if cutoff:
if cutoff < depth:
continue
#print "Looking at vertex ", u, ", depth = ", depth
for v, e in G_succ[u].items():
cost = get_weight(u, v, e)
#print "Looking at vertex ", u, ", edge to ", v
if cost is None:
continue
alt = max(width[v], min(width[u], cost))
if alt > width[v]:
width[v] = alt
Qset.add((v, depth+1))
#print "Updated QSET: ", Qset
return width
def single_source_dijkstra_widest(G, source, cutoff=None,
weight='weight'):
if G.is_multigraph():
get_weight = lambda u, v, data: min(
eattr.get(weight, 1) for eattr in data.values())
else:
get_weight = lambda u, v, data: data.get(weight, 1)
return _dijkstra_custom(G, source, get_weight, cutoff=cutoff)
print ('Networkx version : {} '.format(nx.__version__))
# Command line arguments
argc = len(sys.argv)
if argc<=2:
print("Error: usage is : python3 nvgraph_cpu_ref.py graph.mtx source_vertex")
sys.exit()
mmFile = sys.argv[1]
src = int(sys.argv[2])
print('Reading '+ str(mmFile) + '...')
#Read
M = mmread(mmFile).transpose()
if M is None :
raise TypeError('Could not read the input graph')
# in NVGRAPH tests we read as CSR and feed as CSC, so here we doing this explicitly
M = M.asfptype().tolil().tocsr()
if not M.has_sorted_indices:
M.sort_indices()
# Directed NetworkX graph
Gnx = nx.DiGraph(M)
#widest
print('Solving... ')
t1 = time.time()
widest = single_source_dijkstra_widest(Gnx,source=src)
t2 = time.time() - t1
print('Time : '+str(t2))
print('Writing result ... ')
# fill missing with DBL_MAX
bwidest = np.full(M.shape[0], -sys.float_info.max, dtype=np.float64)
for r in widest.keys():
bwidest[r] = widest[r]
#print bwidest
# write binary
out_fname = os.path.splitext(os.path.basename(mmFile))[0] + '_T.widest_' + str(src) + '.bin'
bwidest.tofile(out_fname, "")
print ('Result is in the file: ' + out_fname)
# write text
#f = open('/tmp/ref_' + os.path.basename(mmFile) + '_widest.txt', 'w')
#f.write(str(widest.values()))
print('Done')
| 0 |
rapidsai_public_repos/nvgraph/test/ref | rapidsai_public_repos/nvgraph/test/ref/nerstrand/README.txt | This is stand alone host app that reads an undirected graph in matrix market format, convert it into CSR, call Nerstrand with default parameters and returns the modularity score of the clustering.
Make sure you have downloaded and installed nerstrand : http://www-users.cs.umn.edu/~lasalle/nerstrand/
You should have libnerstrand.a in <nerstrand_directory>/build/Linux-x86_64/lib, move it to the directory containing this README or adjust the Makefile.
Type "make" to compile the small benchmarking app and "./nerstrand_bench <graph> <number of clusters>" to execute.
For convenience there is also a benchmarking script that calls the benchmarking app (please adjust paths to binary and data sets).
Use the following reference:
@article{lasalle2014nerstrand,
title={Multi-threaded Modularity Based Graph Clustering using the Multilevel Paradigm},
journal = "Journal of Parallel and Distributed Computing ",
year = "2014",
issn = "0743-7315",
doi = "http://dx.doi.org/10.1016/j.jpdc.2014.09.012",
url = "http://www.sciencedirect.com/science/article/pii/S0743731514001750",
author = "Dominique LaSalle and George Karypis"
}
| 0 |
rapidsai_public_repos/nvgraph/test/ref | rapidsai_public_repos/nvgraph/test/ref/nerstrand/mm_host.hxx | #pragma once
#include <stdio.h>
extern "C" {
#include "mmio.h"
}
/// Read matrix properties from Matrix Market file
/** Matrix Market file is assumed to be a sparse matrix in coordinate
* format.
*
* @param f File stream for Matrix Market file.
* @param tg Boolean indicating whether to convert matrix to general
* format (from symmetric, Hermitian, or skew symmetric format).
* @param t (Output) MM_typecode with matrix properties.
* @param m (Output) Number of matrix rows.
* @param n (Output) Number of matrix columns.
* @param nnz (Output) Number of non-zero matrix entries.
* @return Zero if properties were read successfully. Otherwise
* non-zero.
*/
template <typename IndexType_>
int mm_properties(FILE * f, int tg, MM_typecode * t,
IndexType_ * m, IndexType_ * n,
IndexType_ * nnz) {
// Read matrix properties from file
int mint, nint, nnzint;
if(fseek(f,0,SEEK_SET)) {
fprintf(stderr, "Error: could not set position in file\n");
return -1;
}
if(mm_read_banner(f,t)) {
fprintf(stderr, "Error: could not read Matrix Market file banner\n");
return -1;
}
if(!mm_is_matrix(*t) || !mm_is_coordinate(*t)) {
fprintf(stderr, "Error: file does not contain matrix in coordinate format\n");
return -1;
}
if(mm_read_mtx_crd_size(f,&mint,&nint,&nnzint)) {
fprintf(stderr, "Error: could not read matrix dimensions\n");
return -1;
}
if(!mm_is_pattern(*t) && !mm_is_real(*t) &&
!mm_is_integer(*t) && !mm_is_complex(*t)) {
fprintf(stderr, "Error: matrix entries are not valid type\n");
return -1;
}
*m = mint;
*n = nint;
*nnz = nnzint;
// Find total number of non-zero entries
if(tg && !mm_is_general(*t)) {
// Non-diagonal entries should be counted twice
IndexType_ nnzOld = *nnz;
*nnz *= 2;
// Diagonal entries should not be double-counted
int i; int st;
for(i=0; i<nnzOld; ++i) {
// Read matrix entry
IndexType_ row, col;
double rval, ival;
if (mm_is_pattern(*t))
st = fscanf(f, "%d %d\n", &row, &col);
else if (mm_is_real(*t) || mm_is_integer(*t))
st = fscanf(f, "%d %d %lg\n", &row, &col, &rval);
else // Complex matrix
st = fscanf(f, "%d %d %lg %lg\n", &row, &col, &rval, &ival);
if(ferror(f) || (st == EOF)) {
fprintf(stderr, "Error: error %d reading Matrix Market file (entry %d)\n", st, i+1);
return -1;
}
// Check if entry is diagonal
if(row == col)
--(*nnz);
}
}
return 0;
}
/// Read Matrix Market file and convert to COO format matrix
/** Matrix Market file is assumed to be a sparse matrix in coordinate
* format.
*
* @param f File stream for Matrix Market file.
* @param tg Boolean indicating whether to convert matrix to general
* format (from symmetric, Hermitian, or skew symmetric format).
* @param nnz Number of non-zero matrix entries.
* @param cooRowInd (Output) Row indices for COO matrix. Should have
* at least nnz entries.
* @param cooColInd (Output) Column indices for COO matrix. Should
* have at least nnz entries.
* @param cooRVal (Output) Real component of COO matrix
* entries. Should have at least nnz entries. Ignored if null
* pointer.
* @param cooIVal (Output) Imaginary component of COO matrix
* entries. Should have at least nnz entries. Ignored if null
* pointer.
* @return Zero if matrix was read successfully. Otherwise non-zero.
*/
template <typename IndexType_, typename ValueType_>
int mm_to_coo(FILE *f, int tg, IndexType_ nnz,
IndexType_ * cooRowInd, IndexType_ * cooColInd,
ValueType_ * cooRVal , ValueType_ * cooIVal) {
// Read matrix properties from file
MM_typecode t;
int m, n, nnzOld;
if(fseek(f,0,SEEK_SET)) {
fprintf(stderr, "Error: could not set position in file\n");
return -1;
}
if(mm_read_banner(f,&t)) {
fprintf(stderr, "Error: could not read Matrix Market file banner\n");
return -1;
}
if(!mm_is_matrix(t) || !mm_is_coordinate(t)) {
fprintf(stderr, "Error: file does not contain matrix in coordinate format\n");
return -1;
}
if(mm_read_mtx_crd_size(f,&m,&n,&nnzOld)) {
fprintf(stderr, "Error: could not read matrix dimensions\n");
return -1;
}
if(!mm_is_pattern(t) && !mm_is_real(t) &&
!mm_is_integer(t) && !mm_is_complex(t)) {
fprintf(stderr, "Error: matrix entries are not valid type\n");
return -1;
}
// Add each matrix entry in file to COO format matrix
IndexType_ i; // Entry index in Matrix Market file
IndexType_ j = 0; // Entry index in COO format matrix
for(i=0;i<nnzOld;++i) {
// Read entry from file
int row, col;
double rval, ival;
int st;
if (mm_is_pattern(t)) {
st = fscanf(f, "%d %d\n", &row, &col);
rval = 1.0;
ival = 0.0;
}
else if (mm_is_real(t) || mm_is_integer(t)) {
st = fscanf(f, "%d %d %lg\n", &row, &col, &rval);
ival = 0.0;
}
else // Complex matrix
st = fscanf(f, "%d %d %lg %lg\n", &row, &col, &rval, &ival);
if(ferror(f) || (st == EOF)) {
fprintf(stderr, "Error: error %d reading Matrix Market file (entry %d)\n", st, i+1);
return -1;
}
// Switch to 0-based indexing
--row;
--col;
// Record entry
cooRowInd[j] = row;
cooColInd[j] = col;
if(cooRVal != NULL)
cooRVal[j] = rval;
if(cooIVal != NULL)
cooIVal[j] = ival;
++j;
// Add symmetric complement of non-diagonal entries
if(tg && !mm_is_general(t) && (row!=col)) {
// Modify entry value if matrix is skew symmetric or Hermitian
if(mm_is_skew(t)) {
rval = -rval;
ival = -ival;
}
else if(mm_is_hermitian(t)) {
ival = -ival;
}
// Record entry
cooRowInd[j] = col;
cooColInd[j] = row;
if(cooRVal != NULL)
cooRVal[j] = rval;
if(cooIVal != NULL)
cooIVal[j] = ival;
++j;
}
}
return 0;
}
template <typename IndexType_, typename ValueType_>
void sort(IndexType_ *col_idx, ValueType_ *a, IndexType_ start, IndexType_ end)
{
IndexType_ i, j, it;
ValueType_ dt;
for (i=end-1; i>start; i--)
for(j=start; j<i; j++)
if (col_idx[j] > col_idx[j+1]){
if (a){
dt=a[j];
a[j]=a[j+1];
a[j+1]=dt;
}
it=col_idx[j];
col_idx[j]=col_idx[j+1];
col_idx[j+1]=it;
}
}
template <typename IndexType_, typename ValueType_>
void coo2csr(IndexType_ n, IndexType_ nz, ValueType_ *a, IndexType_ *i_idx, IndexType_ *j_idx,
ValueType_ *csr_a, IndexType_ *col_idx, IndexType_ *row_start)
{
IndexType_ i, l;
for (i=0; i<=n; i++) row_start[i] = 0;
/* determine row lengths */
for (i=0; i<nz; i++) row_start[i_idx[i]+1]++;
for (i=0; i<n; i++) row_start[i+1] += row_start[i];
/* go through the structure once more. Fill in output matrix. */
for (l=0; l<nz; l++){
i = row_start[i_idx[l]];
csr_a[i] = a[l];
col_idx[i] = j_idx[l];
row_start[i_idx[l]]++;
}
/* shift back row_start */
for (i=n; i>0; i--) row_start[i] = row_start[i-1];
row_start[0] = 0;
for (i=0; i<n; i++){
sort (col_idx, csr_a, row_start[i], row_start[i+1]);
}
}
| 0 |
rapidsai_public_repos/nvgraph/test/ref | rapidsai_public_repos/nvgraph/test/ref/nerstrand/mmio.h | /*
* Matrix Market I/O library for ANSI C
*
* See http://math.nist.gov/MatrixMarket for details.
*
*
*/
#ifndef MM_IO_H
#define MM_IO_H
#define MM_MAX_LINE_LENGTH 1025
#define MatrixMarketBanner "%%MatrixMarket"
#define MM_MAX_TOKEN_LENGTH 64
typedef char MM_typecode[4];
char *mm_typecode_to_str(MM_typecode matcode);
int mm_read_banner(FILE *f, MM_typecode *matcode);
int mm_read_mtx_crd_size(FILE *f, int *M, int *N, int *nz);
int mm_read_mtx_array_size(FILE *f, int *M, int *N);
int mm_write_banner(FILE *f, MM_typecode matcode);
int mm_write_mtx_crd_size(FILE *f, int M, int N, int nz);
int mm_write_mtx_array_size(FILE *f, int M, int N);
/********************* MM_typecode query fucntions ***************************/
#define mm_is_matrix(typecode) ((typecode)[0]=='M')
#define mm_is_sparse(typecode) ((typecode)[1]=='C')
#define mm_is_coordinate(typecode)((typecode)[1]=='C')
#define mm_is_dense(typecode) ((typecode)[1]=='A')
#define mm_is_array(typecode) ((typecode)[1]=='A')
#define mm_is_complex(typecode) ((typecode)[2]=='C')
#define mm_is_real(typecode) ((typecode)[2]=='R')
#define mm_is_pattern(typecode) ((typecode)[2]=='P')
#define mm_is_integer(typecode) ((typecode)[2]=='I')
#define mm_is_symmetric(typecode)((typecode)[3]=='S')
#define mm_is_general(typecode) ((typecode)[3]=='G')
#define mm_is_skew(typecode) ((typecode)[3]=='K')
#define mm_is_hermitian(typecode)((typecode)[3]=='H')
int mm_is_valid(MM_typecode matcode); /* too complex for a macro */
/********************* MM_typecode modify fucntions ***************************/
#define mm_set_matrix(typecode) ((*typecode)[0]='M')
#define mm_set_coordinate(typecode) ((*typecode)[1]='C')
#define mm_set_array(typecode) ((*typecode)[1]='A')
#define mm_set_dense(typecode) mm_set_array(typecode)
#define mm_set_sparse(typecode) mm_set_coordinate(typecode)
#define mm_set_complex(typecode)((*typecode)[2]='C')
#define mm_set_real(typecode) ((*typecode)[2]='R')
#define mm_set_pattern(typecode)((*typecode)[2]='P')
#define mm_set_integer(typecode)((*typecode)[2]='I')
#define mm_set_symmetric(typecode)((*typecode)[3]='S')
#define mm_set_general(typecode)((*typecode)[3]='G')
#define mm_set_skew(typecode) ((*typecode)[3]='K')
#define mm_set_hermitian(typecode)((*typecode)[3]='H')
#define mm_clear_typecode(typecode) ((*typecode)[0]=(*typecode)[1]= \
(*typecode)[2]=' ',(*typecode)[3]='G')
#define mm_initialize_typecode(typecode) mm_clear_typecode(typecode)
/********************* Matrix Market error codes ***************************/
#define MM_COULD_NOT_READ_FILE 11
#define MM_PREMATURE_EOF 12
#define MM_NOT_MTX 13
#define MM_NO_HEADER 14
#define MM_UNSUPPORTED_TYPE 15
#define MM_LINE_TOO_LONG 16
#define MM_COULD_NOT_WRITE_FILE 17
/******************** Matrix Market internal definitions ********************
MM_matrix_typecode: 4-character sequence
ojbect sparse/ data storage
dense type scheme
string position: [0] [1] [2] [3]
Matrix typecode: M(atrix) C(oord) R(eal) G(eneral)
A(array) C(omplex) H(ermitian)
P(attern) S(ymmetric)
I(nteger) K(kew)
***********************************************************************/
#define MM_MTX_STR "matrix"
#define MM_ARRAY_STR "array"
#define MM_DENSE_STR "array"
#define MM_COORDINATE_STR "coordinate"
#define MM_SPARSE_STR "coordinate"
#define MM_COMPLEX_STR "complex"
#define MM_REAL_STR "real"
#define MM_INT_STR "integer"
#define MM_GENERAL_STR "general"
#define MM_SYMM_STR "symmetric"
#define MM_HERM_STR "hermitian"
#define MM_SKEW_STR "skew-symmetric"
#define MM_PATTERN_STR "pattern"
/* high level routines */
int mm_write_mtx_crd(char fname[], int M, int N, int nz, int I[], int J[],
double val[], MM_typecode matcode);
int mm_read_mtx_crd_data(FILE *f, int M, int N, int nz, int I[], int J[],
double val[], MM_typecode matcode);
int mm_read_mtx_crd_entry(FILE *f, int *I, int *J, double *real, double *img,
MM_typecode matcode);
int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, int *nz_,
double **val_, int **I_, int **J_);
#endif
| 0 |
rapidsai_public_repos/nvgraph/test/ref | rapidsai_public_repos/nvgraph/test/ref/nerstrand/mmio.cpp | /*
* Matrix Market I/O library for ANSI C
*
* See http://math.nist.gov/MatrixMarket for details.
*
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "mmio.h"
int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, int *nz_,
double **val_, int **I_, int **J_)
{
FILE *f;
MM_typecode matcode;
int M, N, nz;
int i;
double *val;
int *I, *J;
if ((f = fopen(fname, "r")) == NULL)
return -1;
if (mm_read_banner(f, &matcode) != 0)
{
printf("mm_read_unsymetric: Could not process Matrix Market banner ");
printf(" in file [%s]\n", fname);
return -1;
}
if ( !(mm_is_real(matcode) && mm_is_matrix(matcode) &&
mm_is_sparse(matcode)))
{
fprintf(stderr, "Sorry, this application does not support ");
fprintf(stderr, "Market Market type: [%s]\n",
mm_typecode_to_str(matcode));
return -1;
}
/* find out size of sparse matrix: M, N, nz .... */
if (mm_read_mtx_crd_size(f, &M, &N, &nz) !=0)
{
fprintf(stderr, "read_unsymmetric_sparse(): could not parse matrix size.\n");
return -1;
}
*M_ = M;
*N_ = N;
*nz_ = nz;
/* reseve memory for matrices */
I = (int *) malloc(nz * sizeof(int));
J = (int *) malloc(nz * sizeof(int));
val = (double *) malloc(nz * sizeof(double));
*val_ = val;
*I_ = I;
*J_ = J;
/* NOTE: when reading in doubles, ANSI C requires the use of the "l" */
/* specifier as in "%lg", "%lf", "%le", otherwise errors will occur */
/* (ANSI C X3.159-1989, Sec. 4.9.6.2, p. 136 lines 13-15) */
for (i=0; i<nz; i++)
{
fscanf(f, "%d %d %lg\n", &I[i], &J[i], &val[i]);
I[i]--; /* adjust from 1-based to 0-based */
J[i]--;
}
fclose(f);
return 0;
}
int mm_is_valid(MM_typecode matcode)
{
if (!mm_is_matrix(matcode)) return 0;
if (mm_is_dense(matcode) && mm_is_pattern(matcode)) return 0;
if (mm_is_real(matcode) && mm_is_hermitian(matcode)) return 0;
if (mm_is_pattern(matcode) && (mm_is_hermitian(matcode) ||
mm_is_skew(matcode))) return 0;
return 1;
}
int mm_read_banner(FILE *f, MM_typecode *matcode)
{
char line[MM_MAX_LINE_LENGTH];
char banner[MM_MAX_TOKEN_LENGTH];
char mtx[MM_MAX_TOKEN_LENGTH];
char crd[MM_MAX_TOKEN_LENGTH];
char data_type[MM_MAX_TOKEN_LENGTH];
char storage_scheme[MM_MAX_TOKEN_LENGTH];
char *p;
mm_clear_typecode(matcode);
if (fgets(line, MM_MAX_LINE_LENGTH, f) == NULL)
return MM_PREMATURE_EOF;
if (sscanf(line, "%s %s %s %s %s", banner, mtx, crd, data_type,
storage_scheme) != 5)
return MM_PREMATURE_EOF;
for (p=mtx; *p!='\0'; *p=tolower(*p),p++); /* convert to lower case */
for (p=crd; *p!='\0'; *p=tolower(*p),p++);
for (p=data_type; *p!='\0'; *p=tolower(*p),p++);
for (p=storage_scheme; *p!='\0'; *p=tolower(*p),p++);
/* check for banner */
if (strncmp(banner, MatrixMarketBanner, strlen(MatrixMarketBanner)) != 0)
return MM_NO_HEADER;
/* first field should be "mtx" */
if (strcmp(mtx, MM_MTX_STR) != 0)
return MM_UNSUPPORTED_TYPE;
mm_set_matrix(matcode);
/* second field describes whether this is a sparse matrix (in coordinate
storgae) or a dense array */
if (strcmp(crd, MM_SPARSE_STR) == 0)
mm_set_sparse(matcode);
else
if (strcmp(crd, MM_DENSE_STR) == 0)
mm_set_dense(matcode);
else
return MM_UNSUPPORTED_TYPE;
/* third field */
if (strcmp(data_type, MM_REAL_STR) == 0)
mm_set_real(matcode);
else
if (strcmp(data_type, MM_COMPLEX_STR) == 0)
mm_set_complex(matcode);
else
if (strcmp(data_type, MM_PATTERN_STR) == 0)
mm_set_pattern(matcode);
else
if (strcmp(data_type, MM_INT_STR) == 0)
mm_set_integer(matcode);
else
return MM_UNSUPPORTED_TYPE;
/* fourth field */
if (strcmp(storage_scheme, MM_GENERAL_STR) == 0)
mm_set_general(matcode);
else
if (strcmp(storage_scheme, MM_SYMM_STR) == 0)
mm_set_symmetric(matcode);
else
if (strcmp(storage_scheme, MM_HERM_STR) == 0)
mm_set_hermitian(matcode);
else
if (strcmp(storage_scheme, MM_SKEW_STR) == 0)
mm_set_skew(matcode);
else
return MM_UNSUPPORTED_TYPE;
return 0;
}
int mm_write_mtx_crd_size(FILE *f, int M, int N, int nz)
{
if (fprintf(f, "%d %d %d\n", M, N, nz) != 3)
return MM_COULD_NOT_WRITE_FILE;
else
return 0;
}
int mm_read_mtx_crd_size(FILE *f, int *M, int *N, int *nz )
{
char line[MM_MAX_LINE_LENGTH];
int num_items_read;
/* set return null parameter values, in case we exit with errors */
*M = *N = *nz = 0;
/* now continue scanning until you reach the end-of-comments */
do
{
if (fgets(line,MM_MAX_LINE_LENGTH,f) == NULL)
return MM_PREMATURE_EOF;
}while (line[0] == '%');
/* line[] is either blank or has M,N, nz */
if (sscanf(line, "%d %d %d", M, N, nz) == 3)
return 0;
else
do
{
num_items_read = fscanf(f, "%d %d %d", M, N, nz);
if (num_items_read == EOF) return MM_PREMATURE_EOF;
}
while (num_items_read != 3);
return 0;
}
int mm_read_mtx_array_size(FILE *f, int *M, int *N)
{
char line[MM_MAX_LINE_LENGTH];
int num_items_read;
/* set return null parameter values, in case we exit with errors */
*M = *N = 0;
/* now continue scanning until you reach the end-of-comments */
do
{
if (fgets(line,MM_MAX_LINE_LENGTH,f) == NULL)
return MM_PREMATURE_EOF;
}while (line[0] == '%');
/* line[] is either blank or has M,N, nz */
if (sscanf(line, "%d %d", M, N) == 2)
return 0;
else /* we have a blank line */
do
{
num_items_read = fscanf(f, "%d %d", M, N);
if (num_items_read == EOF) return MM_PREMATURE_EOF;
}
while (num_items_read != 2);
return 0;
}
int mm_write_mtx_array_size(FILE *f, int M, int N)
{
if (fprintf(f, "%d %d\n", M, N) != 2)
return MM_COULD_NOT_WRITE_FILE;
else
return 0;
}
/*-------------------------------------------------------------------------*/
/******************************************************************/
/* use when I[], J[], and val[]J, and val[] are already allocated */
/******************************************************************/
int mm_read_mtx_crd_data(FILE *f, int M, int N, int nz, int I[], int J[],
double val[], MM_typecode matcode)
{
int i;
if (mm_is_complex(matcode))
{
for (i=0; i<nz; i++)
if (fscanf(f, "%d %d %lg %lg", &I[i], &J[i], &val[2*i], &val[2*i+1])
!= 4) return MM_PREMATURE_EOF;
}
else if (mm_is_real(matcode))
{
for (i=0; i<nz; i++)
{
if (fscanf(f, "%d %d %lg\n", &I[i], &J[i], &val[i])
!= 3) return MM_PREMATURE_EOF;
}
}
else if (mm_is_pattern(matcode))
{
for (i=0; i<nz; i++)
if (fscanf(f, "%d %d", &I[i], &J[i])
!= 2) return MM_PREMATURE_EOF;
}
else
return MM_UNSUPPORTED_TYPE;
return 0;
}
int mm_read_mtx_crd_entry(FILE *f, int *I, int *J,
double *real, double *imag, MM_typecode matcode)
{
if (mm_is_complex(matcode))
{
if (fscanf(f, "%d %d %lg %lg", I, J, real, imag)
!= 4) return MM_PREMATURE_EOF;
}
else if (mm_is_real(matcode))
{
if (fscanf(f, "%d %d %lg\n", I, J, real)
!= 3) return MM_PREMATURE_EOF;
}
else if (mm_is_pattern(matcode))
{
if (fscanf(f, "%d %d", I, J) != 2) return MM_PREMATURE_EOF;
}
else
return MM_UNSUPPORTED_TYPE;
return 0;
}
/************************************************************************
mm_read_mtx_crd() fills M, N, nz, array of values, and return
type code, e.g. 'MCRS'
if matrix is complex, values[] is of size 2*nz,
(nz pairs of real/imaginary values)
************************************************************************/
int mm_read_mtx_crd(char *fname, int *M, int *N, int *nz, int **I, int **J,
double **val, MM_typecode *matcode)
{
int ret_code;
FILE *f;
if (strcmp(fname, "stdin") == 0) f=stdin;
else
if ((f = fopen(fname, "r")) == NULL)
return MM_COULD_NOT_READ_FILE;
if ((ret_code = mm_read_banner(f, matcode)) != 0)
return ret_code;
if (!(mm_is_valid(*matcode) && mm_is_sparse(*matcode) &&
mm_is_matrix(*matcode)))
return MM_UNSUPPORTED_TYPE;
if ((ret_code = mm_read_mtx_crd_size(f, M, N, nz)) != 0)
return ret_code;
*I = (int *) malloc(*nz * sizeof(int));
*J = (int *) malloc(*nz * sizeof(int));
*val = NULL;
if (mm_is_complex(*matcode))
{
*val = (double *) malloc(*nz * 2 * sizeof(double));
ret_code = mm_read_mtx_crd_data(f, *M, *N, *nz, *I, *J, *val,
*matcode);
if (ret_code != 0) return ret_code;
}
else if (mm_is_real(*matcode))
{
*val = (double *) malloc(*nz * sizeof(double));
ret_code = mm_read_mtx_crd_data(f, *M, *N, *nz, *I, *J, *val,
*matcode);
if (ret_code != 0) return ret_code;
}
else if (mm_is_pattern(*matcode))
{
ret_code = mm_read_mtx_crd_data(f, *M, *N, *nz, *I, *J, *val,
*matcode);
if (ret_code != 0) return ret_code;
}
if (f != stdin) fclose(f);
return 0;
}
int mm_write_banner(FILE *f, MM_typecode matcode)
{
char *str = mm_typecode_to_str(matcode);
int ret_code;
ret_code = fprintf(f, "%s %s\n", MatrixMarketBanner, str);
free(str);
if (ret_code !=2 )
return MM_COULD_NOT_WRITE_FILE;
else
return 0;
}
int mm_write_mtx_crd(char fname[], int M, int N, int nz, int I[], int J[],
double val[], MM_typecode matcode)
{
FILE *f;
int i;
if (strcmp(fname, "stdout") == 0)
f = stdout;
else
if ((f = fopen(fname, "w")) == NULL)
return MM_COULD_NOT_WRITE_FILE;
/* print banner followed by typecode */
fprintf(f, "%s ", MatrixMarketBanner);
fprintf(f, "%s\n", mm_typecode_to_str(matcode));
/* print matrix sizes and nonzeros */
fprintf(f, "%d %d %d\n", M, N, nz);
/* print values */
if (mm_is_pattern(matcode))
for (i=0; i<nz; i++)
fprintf(f, "%d %d\n", I[i], J[i]);
else
if (mm_is_real(matcode))
for (i=0; i<nz; i++)
fprintf(f, "%d %d %20.16g\n", I[i], J[i], val[i]);
else
if (mm_is_complex(matcode))
for (i=0; i<nz; i++)
fprintf(f, "%d %d %20.16g %20.16g\n", I[i], J[i], val[2*i],
val[2*i+1]);
else
{
if (f != stdout) fclose(f);
return MM_UNSUPPORTED_TYPE;
}
if (f !=stdout) fclose(f);
return 0;
}
/**
* Create a new copy of a string s. mm_strdup() is a common routine, but
* not part of ANSI C, so it is included here. Used by mm_typecode_to_str().
*
*/
char *mm_strdup(const char *s)
{
int len = strlen(s);
char *s2 = (char *) malloc((len+1)*sizeof(char));
return strcpy(s2, s);
}
char *mm_typecode_to_str(MM_typecode matcode)
{
char buffer[MM_MAX_LINE_LENGTH];
char *types[4];
char *mm_strdup(const char *);
int error =0;
/* check for MTX type */
if (mm_is_matrix(matcode))
types[0] = MM_MTX_STR;
else
error=1;
/* check for CRD or ARR matrix */
if (mm_is_sparse(matcode))
types[1] = MM_SPARSE_STR;
else
if (mm_is_dense(matcode))
types[1] = MM_DENSE_STR;
else
return NULL;
/* check for element data type */
if (mm_is_real(matcode))
types[2] = MM_REAL_STR;
else
if (mm_is_complex(matcode))
types[2] = MM_COMPLEX_STR;
else
if (mm_is_pattern(matcode))
types[2] = MM_PATTERN_STR;
else
if (mm_is_integer(matcode))
types[2] = MM_INT_STR;
else
return NULL;
/* check for symmetry type */
if (mm_is_general(matcode))
types[3] = MM_GENERAL_STR;
else
if (mm_is_symmetric(matcode))
types[3] = MM_SYMM_STR;
else
if (mm_is_hermitian(matcode))
types[3] = MM_HERM_STR;
else
if (mm_is_skew(matcode))
types[3] = MM_SKEW_STR;
else
return NULL;
sprintf(buffer,"%s %s %s %s", types[0], types[1], types[2], types[3]);
return mm_strdup(buffer);
}
| 0 |
rapidsai_public_repos/nvgraph/test/ref | rapidsai_public_repos/nvgraph/test/ref/nerstrand/Makefile | CC=g++
CFLAGS=-O3 -fopenmp
LDFLAGS=-I. -L. libnerstrand.a
EXEC=nerstrand_bench
SOURCES=nerstrand_driver.cpp mmio.cpp
OBJECTS=$(SOURCES:.cpp=.o)
$(EXEC): $(OBJECTS)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
mmio.o: mmio.cpp mmio.h
$(CC) $(CFLAGS) -c $<
nerstand_driver.o: nerstand_driver.cpp mmio.h
$(CC) $(CFLAGS) -c $<
clean:
rm *.o | 0 |
rapidsai_public_repos/nvgraph/test/ref | rapidsai_public_repos/nvgraph/test/ref/nerstrand/nerstrand_driver.cpp | #include <stdio.h>
#include <stddef.h>
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/sysinfo.h>
#include "mmio.h"
#include "mm_host.hxx"
#include "nerstrand.h"
static double second (void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
}
int main(int argc, const char **argv)
{
int m, n, nnz;
double start, stop,r_mod;
cid_t n_clusters;
MM_typecode mc;
if (argc != 3)
{
std::cout<<"Usage : ./nerstrand_bench <graph> <number of clusters>"<<std::endl;
exit(0);
}
FILE* fpin = fopen(argv[1],"r");
n_clusters = atoi(argv[2]);
mm_properties<int>(fpin, 1, &mc, &m, &n, &nnz) ;
// Allocate memory on host
std::vector<int> cooRowIndA(nnz);
std::vector<int> cooColIndA(nnz);
std::vector<double> cooValA(nnz);
std::vector<int> csrRowPtrA(n+1);
std::vector<int> csrColIndA(nnz);
std::vector<double> csrValA(nnz);
mm_to_coo<int,double>(fpin, 1, nnz, &cooRowIndA[0], &cooColIndA[0], &cooValA[0],NULL) ;
coo2csr<int,double> (n, nnz, &cooValA[0], &cooRowIndA[0], &cooColIndA[0], &csrValA[0], &csrColIndA[0],&csrRowPtrA[0]);
fclose(fpin);
vtx_t nerstrand_n = static_cast<vtx_t>(n);
std::vector<adj_t> nerstrand_csrRowPtrA(csrRowPtrA.begin(), csrRowPtrA.end());
std::vector<vtx_t> nerstrand_csrColIndA(csrColIndA.begin(), csrColIndA.end());
std::vector<wgt_t> nerstrand_csrValA(csrValA.begin(), csrValA.end());
std::vector<cid_t> clustering(n);
start = second();
start = second();
#pragma omp_parallel
{
int nerstrand_status = nerstrand_cluster_kway(&nerstrand_n, &nerstrand_csrRowPtrA[0],&nerstrand_csrColIndA[0], &nerstrand_csrValA[0], &n_clusters, &clustering[0], &r_mod);
if (nerstrand_status != NERSTRAND_SUCCESS)
std::cout<<"nerstrand execution failed"<<std::endl;
}
stop = second();
std::cout<<r_mod<<","<<stop-start<<std::endl;
} | 0 |
rapidsai_public_repos/nvgraph/test/ref | rapidsai_public_repos/nvgraph/test/ref/nerstrand/nestrand.sh | #!/bin/bash
nvg_data_prefix="/home/mnaumov/cuda_matrices/p4matrices/dimacs10"
declare -a dataset=(
"$nvg_data_prefix/preferentialAttachment.mtx"
"$nvg_data_prefix/caidaRouterLevel.mtx"
"$nvg_data_prefix/coAuthorsDBLP.mtx"
"$nvg_data_prefix/citationCiteseer.mtx"
"$nvg_data_prefix/coPapersDBLP.mtx"
"$nvg_data_prefix/coPapersCiteseer.mtx"
"/home/afender/modularity/as-Skitter.mtx"
"/home/afender/modularity/hollywood-2009.mtx"
)
for i in "${dataset[@]}"
do
./nerstrand_bench "$i" 7
done
echo
#run only best case according to Spreadsheet 1
./nerstrand_bench "$nvg_data_prefix/preferentialAttachment.mtx" 7
./nerstrand_bench "$nvg_data_prefix/caidaRouterLevel.mtx" 11
./nerstrand_bench "$nvg_data_prefix/coAuthorsDBLP.mtx" 7
./nerstrand_bench "$nvg_data_prefix/citationCiteseer.mtx" 17
./nerstrand_bench "$nvg_data_prefix/coPapersDBLP.mtx" 73
./nerstrand_bench "$nvg_data_prefix/coPapersCiteseer.mtx" 53
./nerstrand_bench "/home/afender/modularity/as-Skitter.mtx" 7
./nerstrand_bench "/home/afender/modularity/hollywood-2009.mtx" 11
| 0 |
rapidsai_public_repos/nvgraph/test/ref | rapidsai_public_repos/nvgraph/test/ref/nerstrand/nerstrand.h | /**
* @file nerstrand.h
* @brief Main header for for nerstrand
* @author Dominique LaSalle <lasalle@cs.umn.edu>
* Copyright 2013, Regents of the University of Minnesota
* @version 1
* @date 2014-01-27
*/
#ifndef NERSTRAND_H
#define NERSTRAND_H
#include <stdint.h>
#include <float.h>
#include <unistd.h>
/******************************************************************************
* VERSION *********************************************************************
******************************************************************************/
#define NERSTRAND_VER_MAJOR 0
#define NERSTRAND_VER_MINOR 5
#define NERSTRAND_VER_SUBMINOR 0
/******************************************************************************
* TYPES ***********************************************************************
******************************************************************************/
#ifndef NERSTRAND_GRAPH_TYPES_DEFINED
#ifdef NERSTRAND_64BIT_VERTICES
typedef uint64_t vtx_t;
#else
typedef uint32_t vtx_t;
#endif
#ifdef NERSTRAND_64BIT_EDGES
typedef uint64_t adj_t;
#else
typedef uint32_t adj_t;
#endif
#ifdef NERSTRAND_DOUBLE_WEIGHTS
typedef double wgt_t;
#else
typedef float wgt_t;
#endif
#endif /* NERSTRAND_GRAPH_TYPES_DEFINED */
#ifdef NERSTRAND_64BIT_CLUSTERS
typedef uint64_t cid_t;
#else
typedef uint32_t cid_t;
#endif
/******************************************************************************
* ENUMS ***********************************************************************
******************************************************************************/
typedef enum nerstrand_error_t {
NERSTRAND_SUCCESS = 1,
NERSTRAND_ERROR_INVALIDOPTIONS,
NERSTRAND_ERROR_INVALIDINPUT,
NERSTRAND_ERROR_NOTENOUGHMEMORY,
NERSTRAND_ERROR_UNIMPLEMENTED,
NERSTRAND_ERROR_UNKNOWN
} nerstrand_error_t;
typedef enum nerstrand_option_t {
NERSTRAND_OPTION_HELP,
NERSTRAND_OPTION_NCLUSTERS,
NERSTRAND_OPTION_NTHREADS,
NERSTRAND_OPTION_SEED,
NERSTRAND_OPTION_NRUNS,
NERSTRAND_OPTION_NREFPASS,
NERSTRAND_OPTION_NINITSOLUTIONS,
NERSTRAND_OPTION_AGGTYPE,
NERSTRAND_OPTION_CONTYPE,
NERSTRAND_OPTION_SPATYPE,
NERSTRAND_OPTION_DISTYPE,
NERSTRAND_OPTION_REFTYPE,
NERSTRAND_OPTION_INITYPE,
NERSTRAND_OPTION_PARTYPE,
NERSTRAND_OPTION_VERBOSITY,
NERSTRAND_OPTION_AGG_RATE,
NERSTRAND_OPTION_CNVTXS_PER_CLUSTER,
NERSTRAND_OPTION_MAXREFMOVES,
NERSTRAND_OPTION_TIME,
NERSTRAND_OPTION_MODSTATS,
NERSTRAND_OPTION_ICSTATS,
NERSTRAND_OPTION_LBSTATS,
NERSTRAND_OPTION_AGGSTATS,
NERSTRAND_OPTION_REFSTATS,
NERSTRAND_OPTION_SUPERNODE_RATIO,
NERSTRAND_OPTION_STOPRATIO,
NERSTRAND_OPTION_STOPCONDITION,
NERSTRAND_OPTION_DEGREE_WEIGHT,
NERSTRAND_OPTION_BLOCKSIZE,
NERSTRAND_OPTION_DISTRIBUTION,
NERSTRAND_OPTION_RESTEP,
__NERSTRAND_OPTION_TERM
} nerstrand_option_t;
typedef enum nerstrand_parttype_t {
NERSTRAND_PARTITION_KWAY,
NERSTRAND_PARTITION_ANYWAY
} nerstrand_parttype_t;
typedef enum nerstrand_aggtype_t {
NERSTRAND_AGGREGATE_RM,
NERSTRAND_AGGREGATE_SHEM,
NERSTRAND_AGGREGATE_AGM,
NERSTRAND_AGGREGATE_AGH,
NERSTRAND_AGGREGATE_RC,
NERSTRAND_AGGREGATE_FC,
NERSTRAND_AGGREGATE_AGC
} nerstrand_aggtype_t;
typedef enum nerstrand_sparsifytype_t {
NERSTRAND_SPARSIFY_NONE,
NERSTRAND_SPARSIFY_RANDOM,
NERSTRAND_SPARSIFY_LIGHT,
NERSTRAND_SPARSIFY_HEAVY,
NERSTRAND_SPARSIFY_DEGREE
} nerstrand_sparsifytype_t;
typedef enum nerstrand_edgeremovaltype_t {
NERSTRAND_EDGEREMOVAL_DROP,
NERSTRAND_EDGEREMOVAL_LOOP,
NERSTRAND_EDGEREMOVAL_DISTRIBUTE,
NERSTRAND_EDGEREMOVAL_PHANTOM
} nerstrand_edgeremovaltype_t;
typedef enum nerstrand_ictype_t {
NERSTRAND_INITIAL_CLUSTERING_BFS,
NERSTRAND_INITIAL_CLUSTERING_RANDOM,
NERSTRAND_INITIAL_CLUSTERING_SEED,
NERSTRAND_INITIAL_CLUSTERING_NEWMAN,
NERSTRAND_INITIAL_CLUSTERING_LP,
NERSTRAND_INITIAL_CLUSTERING_GROW,
NERSTRAND_INITIAL_CLUSTERING_GROWKL,
NERSTRAND_INITIAL_CLUSTERING_VTX,
NERSTRAND_INITIAL_CLUSTERING_RVTX
} nerstrand_ictype_t;
typedef enum nerstrand_contype_t {
NERSTRAND_CONTRACT_SUM
} nerstrand_contype_t;
typedef enum nerstrand_projtype_t {
NERSTRAND_PROJECT_DIRECT,
NERSTRAND_PROJECT_SPARSE
} nerstrand_projtype_t;
typedef enum nerstrand_reftype_t {
NERSTRAND_REFINEMENT_GREEDY,
NERSTRAND_REFINEMENT_RANDOM
} nerstrand_reftype_t;
typedef enum nerstrand_verbosity_t {
NERSTRAND_VERBOSITY_MINIMUM=10,
NERSTRAND_VERBOSITY_LOW=20,
NERSTRAND_VERBOSITY_MEDIUM=30,
NERSTRAND_VERBOSITY_HIGH=40,
NERSTRAND_VERBOSITY_MAXIMUM=50
} nerstrand_verbosity_t;
typedef enum nerstrand_stopcondition_t {
NERSTRAND_STOPCONDITION_EDGES,
NERSTRAND_STOPCONDITION_VERTICES,
NERSTRAND_STOPCONDITION_SIZE
} nerstrand_stopcondition_t;
typedef enum nerstrand_distribution_t {
NERSTRAND_DISTRIBUTION_BLOCK,
NERSTRAND_DISTRIBUTION_CYCLIC,
NERSTRAND_DISTRIBUTION_BLOCKCYCLIC
} nerstrand_distribution_t;
/******************************************************************************
* CONSTANTS *******************************************************************
******************************************************************************/
static const size_t NERSTRAND_NOPTIONS = __NERSTRAND_OPTION_TERM;
static const double NERSTRAND_VAL_OFF = -DBL_MAX;
/******************************************************************************
* FUNCTION PROTOTYPES *********************************************************
******************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Allocate and initialize a set of options for use with the
* nerstrand_cluster_explicit() function.
*
* @return The allocated and initialized options.
*/
double * nerstrand_init_options(void);
/**
* @brief Generate a clustering of a graph with a speficied set of options.
*
* @param r_nvtxs A pointer to the number of vertices in the graph.
* @param xadj The start of the adjacency list of each vertex.
* @param adjncy The vertex at the far end of each edge, indexed by xadj.
* @param adjwgt The weight of each edge, indexed by xadj.
* @param options The options array specifying the parameters for generating
* the clustering.
* @param r_nclusters A pointer to the number of clusters.
* @param cid The cluster assignment for each vertex.
* @param r_mod A pointer to the modularity of the generated clustering.
*
* @return NERSTRAND_SUCCESS unless an error is encountered.
*/
int nerstrand_cluster_explicit(
vtx_t const * r_nvtxs,
adj_t const * xadj,
vtx_t const * adjncy,
wgt_t const * adjwgt,
double const * options,
cid_t * r_nclusters,
cid_t * cid,
double * r_mod);
/**
* @brief Generate a clustering of a graph with specified number of clusters.
*
* @param r_nvtxs A pointer to the number of vertices in the graph.
* @param xadj The start of the adjacency list of each vertex.
* @param adjncy The vertex at the far end of each edge, indexed by xadj.
* @param adjwgt The weight of each edge, indexed by xadj.
* @param r_nclusters A pointer to the number of clusters.
* @param cid The cluster assignment for each vertex.
* @param r_mod A pointer to the modularity of the generated clustering.
*
* @return NERSTRAND_SUCCESS unless an error is encountered.
*/
int nerstrand_cluster_kway(
vtx_t const * r_nvtxs,
adj_t const * xadj,
vtx_t const * adjncy,
wgt_t const * adjwgt,
cid_t const * r_nclusters,
cid_t * cid,
double * r_mod);
/**
* @brief Generate a clustering of a graph with an unspecified number of
* clusters.
*
* @param r_nvtxs A pointer to the number of vertices in the graph.
* @param xadj The start of the adjacency list of each vertex.
* @param adjncy The vertex at the far end of each edge, indexed by xadj.
* @param adjwgt The weight of each edge, indexed by xadj.
* @param r_nclusters A pointer to the number of clusters.
* @param cid The cluster assignment for each vertex.
* @param r_mod A pointer to the modularity of the generated clustering.
*
* @return NERSTRAND_SUCCESS unless an error is encountered.
*/
int nerstrand_cluster_anyway(
vtx_t const * r_nvtxs,
adj_t const * xadj,
vtx_t const * adjncy,
wgt_t const * adjwgt,
cid_t * r_nclusters,
cid_t * cid,
double * r_mod);
#ifdef __cplusplus
}
#endif
#endif
| 0 |
rapidsai_public_repos/nvgraph/test | rapidsai_public_repos/nvgraph/test/generators/plod.cpp | #include <fstream>
#include <assert.h>
#include <stdlib.h>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/plod_generator.hpp>
#include <boost/random/linear_congruential.hpp>
#include <boost/graph/graph_traits.hpp>
void printUsageAndExit()
{
printf("%s", "Usage:./plodg x\n");
printf("%s", "x is the size of the graph\n");
exit(0);
}
int main(int argc, char *argv[])
{
/* " The Power Law Out Degree (PLOD) algorithm generates a scale-free graph from three parameters, n, alpha, and beta.
[...] The value of beta controls the y-intercept of the curve, so that increasing beta increases the average degree of vertices (credit = beta*x^-alpha).
[...] The value of alpha controls how steeply the curve drops off, with larger values indicating a steeper curve. */
// From Boost documentation http://www.boost.org/doc/libs/1_47_0/libs/graph/doc/plod_generator.html
// we use setS aka std::set for edges storage
// so we have at most one edges between 2 vertices
// the extra cost is O(log(E/V)).
typedef boost::adjacency_list<boost::setS> Graph;
typedef boost::plod_iterator<boost::minstd_rand, Graph> SFGen;
if (argc < 2) printUsageAndExit();
int size = atoi (argv[1]);
assert (size > 1 && size < INT_MAX);
double alpha = 2.57; // It is known that web graphs have alpha ~ 2.72.
double beta = size*512+1024; // This will give an average degree ~ 15
// generation
std::cout << "generating ... "<<'\n';
boost::minstd_rand gen;
Graph g(SFGen(gen, size, alpha, beta, false), SFGen(), size);
boost::graph_traits<Graph>::edge_iterator edge, edge_end;
std::cout << "vertices : " << num_vertices(g) <<'\n';
std::cout << "edges : " << num_edges(g) <<'\n';
std::cout << "average degree : "<< static_cast<float>(num_edges(g))/num_vertices(g)<< '\n';
// Print in matrix coordinate real general format
std::cout << "writing ... "<<'\n';
std::stringstream tmp;
tmp <<"local_test_data/plod_graph_" << size << ".mtx";
const std::string filename = tmp.str();
std::ofstream fout(tmp.str().c_str()) ;
if (argv[2]==NULL)
{
// Power law out degree with random weights
fout << "%%MatrixMarket matrix coordinate real general\n";
fout << num_vertices(g) <<' '<< num_vertices(g) <<' '<< num_edges(g) << '\n';
float val;
for( boost::tie(edge, edge_end) = boost::edges(g); edge != edge_end; ++edge)
{
val = (rand()%10)+(rand()%100)*(1e-2f);
fout << boost::source(*edge, g) << ' ' << boost::target(*edge, g)<< ' ' << val << '\n';
}
}
else if (argv[2][0]=='i')
{
// Power law in degree (ie the transpose will have a power law)
// -- Edges only --
// * Wraning * edges will be unsorted, use sort_edges.cpp to sort the dataset.
fout << num_vertices(g) <<' '<< num_edges(g) << '\n';
for( boost::tie(edge, edge_end) = boost::edges(g); edge != edge_end; ++edge)
fout <<boost::target(*edge, g)<< ' ' << boost::source(*edge, g) << '\n';
}
else if (argv[2][0]=='o')
{
// Power law out degree
// -- Edges only --
fout << num_vertices(g) <<' '<< num_edges(g) << '\n';
for( boost::tie(edge, edge_end) = boost::edges(g); edge != edge_end; ++edge)
fout << boost::source(*edge, g) << ' ' << boost::target(*edge, g)<< '\n';
}
else printUsageAndExit();
fout.close();
std::cout << "done!"<<'\n';
return 0;
}
| 0 |
rapidsai_public_repos/nvgraph/test | rapidsai_public_repos/nvgraph/test/generators/Makefile | # Copyright (c) 2015, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.
CXX=g++
CXXFLAGS=-Wall -Ofast -march=native -pipe
all: print_info plodg rmatg
plodg: plod.cpp
$(CXX) $(CXXFLAGS) $< -o $@
rmatg: rmat.cpp
$(CXX) $(CXXFLAGS) $< -o $@
clean:
rm -f rmatg plodg
print_info:
$(info The Boost Graph Library is required)
| 0 |
rapidsai_public_repos/nvgraph/test | rapidsai_public_repos/nvgraph/test/generators/rmat.cpp | #include <fstream>
#include <assert.h>
#include <stdlib.h>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/rmat_graph_generator.hpp>
#include <boost/random/linear_congruential.hpp>
#include <boost/graph/graph_traits.hpp>
void printUsageAndExit()
{
printf("%s", "Usage:./rmatg x\n");
printf("%s", "x is the size of the graph, x>32 (Boost generator hang if x<32)\n");
exit(0);
}
int main(int argc, char *argv[])
{
// RMAT paper http://snap.stanford.edu/class/cs224w-readings/chakrabarti04rmat.pdf
// Boost doc on RMAT http://www.boost.org/doc/libs/1_49_0/libs/graph_parallel/doc/html/rmat_generator.html
typedef boost::adjacency_list<boost::mapS, boost::vecS, boost::directedS> Graph;
typedef boost::unique_rmat_iterator<boost::minstd_rand, Graph> RMATGen;
if (argc < 2) printUsageAndExit();
int size = atoi (argv[1]);
if (size<32) printUsageAndExit();
assert (size > 31 && size < INT_MAX);
const unsigned num_edges = 16 * size;
/************************
* RMAT Gen
************************/
std::cout << "generating ... "<<'\n';
// values of a,b,c,d are from the graph500.
boost::minstd_rand gen;
Graph g(RMATGen(gen, size, num_edges, 0.57, 0.19, 0.19, 0.05, true), RMATGen(), size);
assert (num_edges == boost::num_edges(g));
/************************
* Print
************************/
boost::graph_traits<Graph>::edge_iterator edge, edge_end;
std::cout << "vertices : " << boost::num_vertices(g) <<'\n';
std::cout << "edges : " << boost::num_edges(g) <<'\n';
std::cout << "average degree : "<< static_cast<float>(boost::num_edges(g))/boost::num_vertices(g)<< '\n';
// Print in matrix coordinate real general format
std::cout << "writing ... "<<'\n';
std::stringstream tmp;
tmp <<"local_test_data/rmat_graph_" << size << ".mtx";
const std::string filename = tmp.str();
std::ofstream fout(tmp.str().c_str()) ;
if (argv[2]==NULL)
{
// Power law out degree with random weights
fout << "%%MatrixMarket matrix coordinate real general\n";
fout << boost::num_vertices(g) <<' '<< boost::num_vertices(g) <<' '<< boost::num_edges(g) << '\n';
float val;
for( boost::tie(edge, edge_end) = boost::edges(g); edge != edge_end; ++edge)
{
val = (rand()%10)+(rand()%100)*(1e-2f);
fout << boost::source(*edge, g) << ' ' << boost::target(*edge, g)<< ' ' << val << '\n';
}
}
else if (argv[2][0]=='i')
{
// Power law in degree (ie the transpose will have a power law)
// -- Edges only --
// * Wraning * edges will be unsorted, use sort_edges.cpp to sort the dataset.
fout << boost::num_vertices(g) <<' '<< boost::num_edges(g) << '\n';
for( boost::tie(edge, edge_end) = boost::edges(g); edge != edge_end; ++edge)
fout <<boost::target(*edge, g)<< ' ' << boost::source(*edge, g) << '\n';
}
else if (argv[2][0]=='o')
{
// Power law out degree
// -- Edges only --
fout << boost::num_vertices(g) <<' '<< boost::num_edges(g) << '\n';
for( boost::tie(edge, edge_end) = boost::edges(g); edge != edge_end; ++edge)
fout << boost::source(*edge, g) << ' ' << boost::target(*edge, g)<< '\n';
}
else printUsageAndExit();
fout.close();
std::cout << "done"<<'\n';
return 0;
}
| 0 |
rapidsai_public_repos/nvgraph/test/generators | rapidsai_public_repos/nvgraph/test/generators/convertors/README.txt | -----------------------
Compile
-----------------------
> make
-----------------------
Run
-----------------------
To preprocess a set of edges in matrix market patern format
> ./pprocess.sh edges.dat
You can run separately
Sort :
> ./sort edges.dat
Compute H :
> ./H edges.dat
Compute H transposed and dangling node vector
> ./HTA H.mtx
Convert in AmgX binary format
> ./mtob HTA.mtx
-----------------------
Input
-----------------------
The format for sort and H is matrix market patern format
example :
%%comment
% as much comments as you want
%...
size size nonzero
a b
c d
a e
e a
.
.
.
[a-e] are in N*
The format for HTA and mtob is matrix market coordinate format
%%comment
% as much comments as you want
%...
size size nonzero
a b f
c d g
a e h
e a i
.
.
.
[a-e] are in N*
[f-i] are in R | 0 |
rapidsai_public_repos/nvgraph/test/generators | rapidsai_public_repos/nvgraph/test/generators/convertors/H_to_HtSorted_and_a.cpp | #include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <algorithm> // std::sort
#include <vector> // std::vector
// This code transpose a matrix H and compute the flag vector of empty rows a.
// We assume that H is row-substochastic, in MatrixMarket format and data are sorted by row id
// The output is filename_T.filetype, H is printed first then a is printed.
struct elt {
long int r;
long int c;
double v;
};
void printUsageAndExit()
{
printf("%s", "Fatal Error\n");
printf("%s", "Usage: ./HTA H.mtx\n");
printf("%s", "NOTE1: H is the row-substochastic matrix of a graph\n");
printf("%s", "NOTE2: H is in MatrixMarket coordinate real general format\n");
printf("%s", "NOTE3: Data are sorted by row id\n");
printf("%s", "Output : H^t and the bookmark vector of empty rows\n");
printf("%s", "***This output fits the input of AMGX PageRank***\n");
exit(0);
}
inline bool operator< (const elt& a, const elt& b)
{ // ordered by row and then by colum inside a row
return a.r<b.r || (a.r==b.r && a.c<b.c ) ;
}
int main (int argc, char *argv[])
{
// Check args
if (argc == 1) printUsageAndExit();
// Vars
long int n, nz, start, i = 0 ,j, k, lastr;
double v;
char outp[128], cc;
FILE *fpin = NULL, *fpout = NULL;
elt e;
std::vector<struct elt> A;
std::vector<unsigned int> a;
// Get I/O names
// The output is filename_T
while (argv[1][i] != '\0')
{outp[i] = argv[1][i];i++;}
outp[i] = '_'; i++;
outp[i] = 'T';i++;
outp[i]='\0';
// Open files
fpin = fopen(argv[1],"r");
fpout = fopen(outp,"w");
if (!fpin || !fpout)
{
printf("%s", "Fatal Error : I/O fail\n");
exit(0);
}
// Skip lines starting with "%%""
do
{
cc = fgetc(fpin);
if (cc == '%') fgets(outp,128,fpin);
}
while (cc == '%');
fseek( fpin, -1, SEEK_CUR );
// Get n and nz
fscanf(fpin,"%ld",&n);
fscanf(fpin,"%ld",&n);
fscanf(fpin,"%ld",&nz);
// Print format and size
fprintf(fpout, "%s", "%%");
fprintf(fpout,"MatrixMarket matrix coordinate real general\n");
fprintf(fpout, "%s", "%%");
fprintf(fpout,"AMGX rhs\n");
fprintf(fpout,"%ld %ld %ld\n",n, n, nz);
// Empty rows at the begining
fscanf(fpin,"%ld",&e.c);
fscanf(fpin,"%ld",&e.r);
fscanf(fpin,"%lf",&e.v);
A.push_back(e);
for (j=0; j<static_cast<int>(e.c)-1; j++)
{
std::cout<<e.c<<' '<<e.r<<' '<<e.v<<'\n';
a.push_back(1);
}
// Loop
for (i=0; i< nz-1;i++)
{
lastr = e.c;
fscanf(fpin,"%ld",&e.c);
fscanf(fpin,"%ld",&e.r);
fscanf(fpin,"%lf",&e.v);
A.push_back(e);
if (e.c > lastr)
{
if (e.c > lastr+1)
{
a.push_back(0);
//Successive empty rows
for (k=0; k<static_cast<int>(e.c)-lastr-1; k++)
a.push_back(1);
}
else
a.push_back(0);
}
}
a.push_back(0);
// Empty rows at the end
for (k=a.size(); k<n; k++)
{
a.push_back(1);
}
std::sort (A.begin(), A.end());
for (std::vector<struct elt>::iterator it = A.begin() ; it != A.end(); ++it)
fprintf(fpout,"%ld %ld %.9f\n",it->r, it->c, it->v);
for (std::vector<unsigned int>::iterator it = a.begin() ; it != a.end(); ++it)
fprintf(fpout,"%u\n",*it);
return 0;
}
| 0 |
rapidsai_public_repos/nvgraph/test/generators | rapidsai_public_repos/nvgraph/test/generators/convertors/binary_converter.cpp | #include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <algorithm> // std::sort etc.
#include <vector> // std::vector
#include <iostream> // std::cout
typedef int idx_t;
typedef double val_t;
void printUsageAndExit()
{
printf("%s", "Usage:./mtob M.mtx\n");
printf("%s", "NOTE1: M is square, in MatrixMarket coordinate real general format\n");
printf("%s", "NOTE2: Data are sorted by row id\n");
exit(0);
}
void print_csr( std::vector<idx_t> &row_ptrs, std::vector<idx_t> &col_indices, std::vector<val_t> &val)
{
for (std::vector<idx_t>::iterator it = row_ptrs.begin(); it != row_ptrs.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
for (std::vector<idx_t>::iterator it = col_indices.begin(); it != col_indices.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
for (std::vector<val_t>::iterator it = val.begin(); it != val.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
}
// Generates csr from matrix market format
void read_csr( FILE *fpin,
idx_t n,
idx_t nz,
std::vector<idx_t> &row_weight,
std::vector<idx_t> &row_ptrs,
std::vector<idx_t> &col_indices,
std::vector<val_t> &val)
{
idx_t weight=0, i=0 ,j=0, k=0, lastr=0, r=0, c=0;
double v;
// Empty rows at the begining
fscanf(fpin,"%d",&r);
fscanf(fpin,"%d",&c);
fscanf(fpin,"%lf",&v);
row_ptrs.push_back(0);
col_indices.push_back(c-1);
val.push_back(v);
weight++;
for (j=0; j<r-1; j++)
{
row_ptrs.push_back(0);
row_weight.push_back(0);
}
// Loop
for (i=1; i< nz;i++)
{
lastr = r;
fscanf(fpin,"%d",&r);
fscanf(fpin,"%d",&c);
fscanf(fpin,"%lf",&v);
col_indices.push_back(c-1);
val.push_back(v);
if (lastr == r)
weight++;
else if (lastr < r)// new row
{
row_ptrs.push_back(row_ptrs.back()+weight);
row_weight.push_back(weight);
//Successive empty rows
for (k=row_weight.size(); k<r-1; k++)
{
row_ptrs.push_back(row_ptrs.back());
row_weight.push_back(0);
}
weight = 1;
}
else
{
printf("%s", "Fatal Error : Data have to be sorted by row id\n");
exit(0);
}
}
row_ptrs.push_back(row_ptrs.back()+weight);
row_weight.push_back(weight);
// Empty rows at the end
for (k=row_weight.size(); k<n; k++)
{
row_ptrs.push_back(row_ptrs.back());
row_weight.push_back(0);
}
}
void read_vector_mtx( FILE *fpin,
idx_t n,
std::vector<val_t> &a)
{
val_t v;
for (idx_t i=0; i< n;i++)
{
fscanf(fpin,"%lf",&v);
a.push_back(v);
}
}
void write_csr_bin (char *argv[],
idx_t n,
idx_t nz,
std::vector<idx_t> &row_weight,
std::vector<idx_t> &row_ptrs,
std::vector<idx_t> &col_indices,
std::vector<val_t> &val,
std::vector<val_t> &a
)
{
idx_t i;
char outp [128];
// Generate output name
while (argv[1][i] != '\0')
{
outp[i] = argv[1][i];
i++;
}
outp[i] = '_';i++;
outp[i] = 'b';i++;
outp[i] = 'i';i++;
outp[i] = 'n';i++;
outp[i]='\0';
FILE *fpout = NULL;
fpout = fopen(outp,"w");
if (!fpout)
{
printf("%s", "Fatal Error : I/O fail\n");
exit(0);
}
const char header [] = "%%NVAMGBinary\n";
const int system_header_size = 9;
uint32_t system_flags [] = { 1, 1, 0, 0, 0, 1, 1, n, nz };
fwrite(header, sizeof(char), strlen(header), fpout);
fwrite(system_flags, sizeof(uint32_t), system_header_size, fpout);
fwrite(&row_ptrs[0], sizeof(idx_t), row_ptrs.size(), fpout);
fwrite(&col_indices[0], sizeof(idx_t), col_indices.size(), fpout);
fwrite(&val[0], sizeof(val_t), val.size(), fpout);
fwrite(&a[0], sizeof(val_t), a.size(), fpout);
fclose(fpout);
}
int main (int argc, char **argv)
{
// Vars
idx_t i = 0;
idx_t n=0, m=0, nz=0, nparts=0, sym=0;
char dum[128], cc;
FILE *fpin = NULL;
std::vector<idx_t> row_ptrs, col_indices, row_weight;
std::vector<val_t> a , val;
// Check args
if (argc != 2) printUsageAndExit();
// Open file
fpin = fopen(argv[1],"r");
if (!fpin)
{
printf("%s", "Fatal Error : I/O fail\n");
exit(0);
}
// Skip lines starting with "%%""
do
{
cc = fgetc(fpin);
if (cc == '%') fgets(dum,128,fpin);
}
while (cc == '%');
fseek( fpin, -1, SEEK_CUR );
// Get n and nz
fscanf(fpin,"%ld",&n);
fscanf(fpin,"%ld",&m);
fscanf(fpin,"%ld",&nz);
if (n != m)
{
printf("%s", "Fatal Error : The matrix is not square\n");
exit(0);
}
//printf("Reading...\n");
read_csr(fpin, n, nz, row_weight, row_ptrs, col_indices, val);
read_vector_mtx(fpin, n, a);
//printf("Writing...\n");
write_csr_bin(argv, n, nz, row_weight, row_ptrs, col_indices, val,a);
//printf("Success!\n");
return 0;
}
| 0 |
rapidsai_public_repos/nvgraph/test/generators | rapidsai_public_repos/nvgraph/test/generators/convertors/pprocess.sh | #!/bin/sh
edges="$1"
echo "Starting Sort on $edges..."
./sort $edges
echo "Done"
tmp="_s"
sedges=$edges$tmp
echo "Starting H on $sedges ..."
./H $sedges
echo "Done"
tmp="_mtx"
matrix=$sedges$tmp
#delete soted edges
rm $sedges
echo "Starting HTa on $matrix ..."
./HTA $matrix
tmp="_T"
outp=$edges$tmp
outpp=$matrix$tmp
mv $outpp $outp
#delete H
rm $matrix
echo "Starting binary conversion ..."
./mtob $outp
echo "Done"
| 0 |
rapidsai_public_repos/nvgraph/test/generators | rapidsai_public_repos/nvgraph/test/generators/convertors/Makefile | CC=g++
CFLAGS=-O3 -march=native -pipe -w
LDFLAGS=-lm
all: sort HTA H mtob
sort: sort_eges.cpp
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
HTA: H_to_HtSorted_and_a.cpp
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
H: edges_to_H.cpp
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
mtob: binary_converter.cpp
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
clean:
rm sort HTA mtob
| 0 |
rapidsai_public_repos/nvgraph/test/generators | rapidsai_public_repos/nvgraph/test/generators/convertors/sort_eges.cpp | #include <stdio.h>
#include <stdlib.h>
#include <algorithm> // std::sort
#include <vector> // std::vector
struct edge {
unsigned long int r;
unsigned long int c;
};
void printUsageAndExit()
{
printf("%s", "Fatal Error\n");
printf("%s", "Usage: ./sort edges.dat\n");
printf("%s", "Input : Graph in matrix market parttern format");
printf("%s", "Output : Graph with sorted edges in matrix market parttern format\n");
exit(0);
}
inline bool operator< (const edge& a, const edge& b){ if(a.r<b.r) return true; else return false; }
int main (int argc, char *argv[])
{
// Check args
if (argc != 2) printUsageAndExit();
// Vars
unsigned long int n, nz, i = 0, current_r, nbr = 1;
int ok;
double scal;
char outp[128], cc;
FILE *fpin = NULL, *fpout = NULL;
edge e;
std::vector<struct edge> edges;
// Get I/O names
// The output is filename.mtx
while (argv[1][i] != '\0')
{outp[i] = argv[1][i];i++;}
outp[i] = '_'; i++;
outp[i] = 's';i++;
outp[i]='\0';
// Open files
fpin = fopen(argv[1],"r");
fpout = fopen(outp,"w");
if (!fpin || !fpout)
{
printf("%s", "Fatal Error : I/O fail\n");
exit(0);
}
// Skip lines starting with "%""
do
{
cc = fgetc(fpin);
if (cc == '%') fgets(outp,128,fpin);
}
while (cc == '%');
fseek( fpin, -1, SEEK_CUR );
// Get n and nz
fscanf(fpin,"%lu",&n);
//fscanf(fpin,"%lu",&n);
fscanf(fpin,"%lu",&nz);
fprintf(fpout,"%lu %lu %lu\n",n, n, nz);
// Read the first edge
ok = fscanf(fpin,"%lu",&e.r);
if (ok)
{
fscanf(fpin,"%lu",&e.c);
edges.push_back(e);
}
else
{
printf("%s", "Fatal Error : Wrong data format\n");
exit(0);
}
//Loop
for (i=0; i<nz-1; i++)
{
fscanf(fpin,"%lu",&e.r);
fscanf(fpin,"%lu",&e.c);
edges.push_back(e);
}
std::sort (edges.begin(), edges.end());
for (std::vector<struct edge>::iterator it = edges.begin() ; it != edges.end(); ++it)
fprintf(fpout,"%lu %lu\n",it->r, it->c);
return 0;
}
| 0 |
rapidsai_public_repos/nvgraph/test/generators | rapidsai_public_repos/nvgraph/test/generators/convertors/edges_to_H.cpp | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
struct edge {
unsigned long int r;
unsigned long int c;
};
void printUsageAndExit()
{
printf("%s", "Fatal Error\n");
printf("%s", "Usage: ./H edges.dat\n");
printf("%s", "Input : Graph given as a sorted set of edges\n");
printf("%s", "Output : Row sub-stochastic matrix in MatrixMarket format\n");
exit(0);
}
int main (int argc, char *argv[])
{
// Check args
if (argc != 2) printUsageAndExit();
// Vars
unsigned long int n, nz, i = 0, current_r, nbr = 1;
int ok;
double scal;
char outp[128], cc;
FILE *fpin = NULL, *fpout = NULL;
edge e;
std::vector<struct edge> row;
// Get I/O names
// The output is filename.mtx
while (argv[1][i] != '\0')
{outp[i] = argv[1][i];i++;}
outp[i] = '_'; i++;
outp[i] = 'm';i++;outp[i] = 't';i++;outp[i] = 'x';i++;
outp[i]='\0';
// Open files
fpin = fopen(argv[1],"r");
fpout = fopen(outp,"w");
if (!fpin || !fpout)
{
printf("%s", "Fatal Error : I/O fail\n");
exit(0);
}
// Get n and nz
fscanf(fpin,"%lu",&n);
fscanf(fpin,"%lu",&n);
fscanf(fpin,"%lu",&nz);
fprintf(fpout, "%s", "%%" );
fprintf(fpout,"MatrixMarket matrix coordinate real general\n");
fprintf(fpout,"%lu %lu %lu\n",n, n, nz);
// Read the first edge
ok = fscanf(fpin,"%lu",&e.r);
if (ok)
{
fscanf(fpin,"%lu",&e.c);
current_r = e.r;
row.push_back(e);
}
else
{
printf("%s", "Fatal Error : Wrong data format\n");
exit(0);
}
//Loop
for (i=0; i<nz-1; i++)
{
fscanf(fpin,"%lu",&e.r);
fscanf(fpin,"%lu",&e.c);
if (current_r == e.r)
{
nbr++;
}
else
{
current_r = e.r;
scal = 1.0/nbr;
for (std::vector<struct edge>::iterator it = row.begin() ; it != row.end(); ++it)
fprintf(fpout,"%lu %lu %.9lf\n",it->r, it->c, scal);
row.clear();
nbr = 1;
}
row.push_back(e);
}
// Last print
scal = 1.0/nbr;
for (std::vector<struct edge>::iterator it = row.begin() ; it != row.end(); ++it)
fprintf(fpout,"%lu %lu %.9f\n",it->r, it->c, scal);
return 0;
}
| 0 |
rapidsai_public_repos/nvgraph/test | rapidsai_public_repos/nvgraph/test/local_test_data/small_T.mtx | %%MatrixMarket matrix coordinate real general
%%AMGX rhs
6 6 10
1 3 0.333333000
2 1 0.500000000
2 3 0.333333000
3 1 0.500000000
4 5 0.500000000
4 6 1.000000000
5 3 0.333333000
5 4 0.500000000
6 4 0.500000000
6 5 0.500000000
0
1
0
0
0
0
| 0 |
rapidsai_public_repos/nvgraph/test | rapidsai_public_repos/nvgraph/test/local_test_data/small.mtx | %%MatrixMarket matrix coordinate real general
6 6 10
1 2 0.500000
1 3 0.500000
3 1 0.333333
3 2 0.333333
3 5 0.333333
4 5 0.500000
4 6 0.500000
5 4 0.500000
5 6 0.500000
6 4 1.000000
| 0 |