-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathngrams.erl
More file actions
32 lines (23 loc) · 1.47 KB
/
ngrams.erl
File metadata and controls
32 lines (23 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
-module(ngrams).
-export([ngrams/5]).
-import(handle_triplets, [make_triplet_counters/4, make_triplet_generators/4]).
ngrams(ListOfFiles, ListOfHosts, NumberOfTripletGenerators, NumberOfTripletCounters, ChunkSize) ->
StartTime = now(),
%FIRST, very important!!!
%Have to ping all nodes based off of hosts so that round_robin doesn't poop itself
net_adm:world_list(ListOfHosts),
%now, [node()|nodes()] will get all nodes instead of just the ones running on the box that round_robin happens on (this one)
%create ets table for counting total triplet counts
TableName = overallCounter,
%ets:new(TableName, [ordered_set,named_table]),
%create counter_loop for round robin distribution of processes
CounterLoop = spawn(node_handler, counter_loop, [0]),
%spawn process to handle total counts
OverallCounterNode = node_handler:round_robin(CounterLoop),
OverallCounterPID = spawn(OverallCounterNode, handle_triplets, overall_counter, [StartTime, length(ListOfFiles), 0, 0, -1, 0, true]),
%make triplet counter list
TripletCounterList = make_triplet_counters(NumberOfTripletCounters, [], OverallCounterPID, CounterLoop),
%make triplet generator list
TripletGeneratorList = make_triplet_generators(NumberOfTripletGenerators, [], TripletCounterList, CounterLoop),
%Start handling files n stuff
file_handler:processFiles(ListOfFiles, CounterLoop, ChunkSize, TripletGeneratorList, OverallCounterPID).