[ Skip to the content ]

Institute of Formal and Applied Linguistics Wiki


[ Back to the navigation ]

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
spark:spark-introduction [2014/11/11 09:09]
straka
spark:spark-introduction [2015/07/27 17:51]
straka
Line 51: Line 51:
 val counts = words.map(word => (word,1)).reduceByKey((c1,c2) => c1+c2) val counts = words.map(word => (word,1)).reduceByKey((c1,c2) => c1+c2)
 val sorted = counts.sortBy({case (word, count) => count}, ascending=false) val sorted = counts.sortBy({case (word, count) => count}, ascending=false)
-sorted.saveAsTextFile('output')+sorted.saveAsTextFile("output")
  
 // Alternatively without variables and using placeholders in lambda parameters: // Alternatively without variables and using placeholders in lambda parameters:
Line 71: Line 71:
  
 lines = sc.textFile("/net/projects/spark-example-data/points", sc.defaultParallelism) lines = sc.textFile("/net/projects/spark-example-data/points", sc.defaultParallelism)
-data = lines.map(lambda line: map(float, line.split())).cache()+data = lines.map(lambda line: np.array(map(float, line.split()))).cache()
  
 K = 50 K = 50
Line 97: Line 97:
 print "Final centers: " + str(centers) print "Final centers: " + str(centers)
 </file> </file>
-The implementation starts by loading the data and caching them in memory using ''cache''. Then, standard iterative algorithm is performed, running in parallel. +The implementation starts by loading the data points and caching them in memory using ''cache''. Then, standard iterative algorithm is performed, running in parallel and synchronizing where necessary.
  
 Note that explicit broadcasting used for ''centers'' object is not strictly needed -- if we used ''old_centers = centers'', the example would work too, but it would send a copy of ''old_centers'' to //every distributed task//, instead of once to every machine. Note that explicit broadcasting used for ''centers'' object is not strictly needed -- if we used ''old_centers = centers'', the example would work too, but it would send a copy of ''old_centers'' to //every distributed task//, instead of once to every machine.

[ Back to the navigation ] [ Back to the content ]