Skip to content

Instantly share code, notes, and snippets.

@disa-mhembere
Created April 5, 2015 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save disa-mhembere/a68ff81108c3d3c1d2bc to your computer and use it in GitHub Desktop.
Save disa-mhembere/a68ff81108c3d3c1d2bc to your computer and use it in GitHub Desktop.
Stubs for triangle counting assignment
"""
Author: YOUR NAME HERE
JHED: YOUR JHED HERE
Name: triangle_count.py
Get the list of cycle triangles in the graph
"""
from pyspark import SparkContext
from time import time
import sys, os
#TODO: Possibly define functions up here
# NOTE: Do not change the name/signature of this function
def count_triangles(data, master="local[2]"):
"""
@brief: Count triangles using Spark
@param data: The data location for the input files
@param master: The master URL as defined at
https://spark.apache.org/docs/1.1.0/submitting-applications.html#master-urls
"""
################# NO EDITS HERE ###################
assert not os.path.exists("triangles.out"), "File: triangles.out \
already exists"
sc = SparkContext(master, "Triangle Count")
start = time()
############### END NO EDITS HERE ################
# TODO: Your code goes here!
################# NO EDITS HERE ###################
print "\n\n*****************************************"
print "\nTotal algorithm time: %.4f sec \n" % (time()-start)
print "*****************************************\n\n"""
############### END NO EDITS HERE ################
with open("triangles.out", "wb") as f:
f.write("") # TODO: Loop with f to write your result to file serially
pass
################# NO EDITS HERE ###################
if __name__ == "__main__":
if len(sys.argv) == 2:
print "Counting triangles with master as 'local[2]'"
count_triangles(sys.argv[1])
elif len(sys.argv) == 3:
print "Counting triangles with master as '%s'" % sys.argv[2]
count_triangles(sys.argv[1], sys.argv[2])
else:
sys.stderr.write("\nusage: SPARK_ROOT/bin/spark-submit \
example/python/tri_count.py data_dir [master-url]")
exit(1)
############### NO EDITS BELOW EITHER ################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment