i need to write factorial function(n!) in parallel computing on EREW PRAM system. assume that we have n proccessors. the complexity should be log n. how can i do this?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
The question makes no sense, since you're looking for an algorithm whose complexity (
log n
) increases as you add processors (i.e. increasen
).I am guessing that what you're meant to do is split the product
1*2*3*...*k
inton
blocks of equal size, compute each sub-product on a separate processor, and then multiply then
results together.In general you can divide the work N times for N processors and compute each independently. You can combine the results by multiplying the answers for each piece of work. e.g. the first task performed m!, the next (2m)!/m!, the third (3m!)/(2m!) etc. When you multiple the results you get n!.
BTW: You wouldn't do this for small values of
n
e.g less than 1000 because the overhead of starting new threads/task can be greater than the time it takes to do this in a single thread.I suspect pseudo code won't be enough so here is an example
on an 3.72 GHz i7 prints