If I have an algorithm with two parallel for and I want to analyze the span of the algorithm, what do I have to do?
For example
parallel for a=2 to n
parallel for 开发者_StackOverflowb=1 to a-1
My guess is the span is theta(lg(n)*lg(n)) but I'm not sure. :) Someone who can help or give a hint?
I am assuming you want the time complexity of this algorithm. Since time complexity is NOT how much time the algorithm actually takes, but rather how much operations are needed for it [a quote supporting this claim follows], the time complexity of this algorithm is O(n^2)
, as it was if it was not parallel.
from the wiki page: Time complexity is commonly estimated by counting the number of elementary operations performed by the algorithm, where an elementary operation takes a fixed amount of time to perform
Why don't we care for the fact the algorithm is parallel?
Usually, our cluster size is fixed, and does not depend on the input [n]. let the cluster size be k
[meaning, we can perform k
operations simultaneously and the algorithm is O(n^2)
[for simplicity assume exactly n^2
]
assume we have an input of size 100, then it will 'take' (100^2)/k
time. if it was of size 1,000, it would take (1000^2)/k
, and for n elements: (n^2)/k
, as you can see, the k is a constant, and the fact that the program is parallel does not change the complexity. Being able to do k
operations at once, is not better [and even worth, but that's for another thread] then a computer k
time faster.
精彩评论