Created
February 5, 2014 20:36
-
-
Save jasonmp85/8832488 to your computer and use it in GitHub Desktop.
Parallelism Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <math.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
static const int ITERATIONS = 2134113216; | |
static double do_work(int worker_num, int concurrency) | |
{ | |
int chunk_size = ITERATIONS / concurrency; | |
int start_num = chunk_size * worker_num; | |
int i; | |
double sum = 0.0; | |
for (i = start_num; i < start_num + chunk_size; i++) | |
{ | |
sum += sqrt((double) i); | |
} | |
return sum; | |
} | |
int main (int argc, char const *argv[]) | |
{ | |
int worker_num = 0; | |
int concurrency = 0; | |
double result = 0.0; | |
if (argc == 3) | |
{ | |
worker_num = atoi(argv[1]); | |
concurrency = atoi(argv[2]); | |
result = (worker_num < concurrency) ? do_work(worker_num, concurrency) : 0.0; | |
printf("%0.3f\n", result); | |
return 0; | |
} | |
else | |
{ | |
(void) fputs("Pass exactly two arguments\n", stderr); | |
return -1; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'parallel' | |
def seconds_elapsed_during(&blk) | |
before = Time.now | |
blk.call | |
after = Time.now | |
return after - before | |
end | |
proc_count = 32 # change to expected maximum | |
warn "Detected #{proc_count} processors..." | |
baseline = nil | |
speedups = 1.upto(proc_count).map do |concurrency| | |
warn "Testing #{concurrency} active workers..." | |
observed = seconds_elapsed_during do | |
`seq 0 #{concurrency - 1} | xargs -L 1 -P #{concurrency} -I% ./a.out % #{concurrency}` | |
end | |
baseline ||= observed | |
speedup = (baseline / observed) - 1 | |
warn ("%0.3f elapsed (%d%% speedup)" % [observed, speedup * 100]) | |
speedup | |
end | |
likely_count = speedups.each_with_index.find { |sp, i| i != sp.round }.last | |
puts likely_count | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See the Karp–Flatt Metric and related paper.