带有Map Reduce的POSIX线程

时间:2018-10-01 19:53:16

标签: c mapreduce pthreads

最近在我的操作系统类中给了我一个作业,该作业解释了我们必须使用Map()和Reduce()函数(在C语言中)来对文本文件中单词的出现频率进行排序和计数。正如我通过一些研究发现的那样,这是一个相当随意和简单的示例,但是我很难理解的是在程序中使用POSIX线程的要求。这是否意味着浮动的Map()和Reduce()函数的伪代码算法不会固有地使用pthread或多个Linux进程?例如...

function map(String name, String document):
  // name: document name
  // document: document contents
  for each word w in document:
    emit (w, 1)

function reduce(String word, Iterator partialCounts):
  // word: a word
  // partialCounts: a list of aggregated partial counts
  sum = 0
  for each pc in partialCounts:
    sum += pc
  emit (word, sum)

我试图在其他地方找到这个答案,但是没有运气。任何建议表示赞赏!

(我不是在寻找项目的代码,只是一个更好的解释)

0 个答案:

没有答案