并行算法
2021/8/31 1:36:03
本文主要是介绍并行算法,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
[root@bogon ~]# echo "foo foo quux labs foo bar zo zoo hying" | python3 mapper.py | sort -k 1,1 | python3 reducer.py ^C [root@bogon ~]# cat reducer.py #! /usr/bin/python3 from operator import itemgetter import sys current_word = None current_count = 0 word = None for line in sys.stdin: words = line.strip() word, count = words.split('\t') try: count = int(count) except ValueError: continue if current_word == word: current_count += count else: if current_word: print("%s\t%s" %(current_word,current_count)) current_count = count current_word = word if current_word == word: print("%s\t%s" %(current_word, current_count))
[root@bogon ~]# cat mapper.py #! /usr/bin/python3 import sys for line in sys.stdin: line = line.strip() words = line.split() for word in words: print('%s\t%s' %(word,1)) [root@bogon ~]#
[root@bogon Python-3.7.5]# echo "foo foo quux labs foo bar zo zoo hying" | python3 mapper.py | more
foo 1
foo 1
quux 1
labs 1
foo 1
bar 1
zo 1
zoo 1
hying 1
[root@bogon ~]# echo "foo foo quux labs foo bar zo zoo hying" | python3 mapper.py | sort -k 1,1 | python3 reducer.py
bar 1
foo 3
hying 1
labs 1
quux 1
zo 1
zoo 1
这篇关于并行算法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-07-04TiDB 资源管控的对撞测试以及最佳实践架构
- 2024-07-03万字长文聊聊Web3的组成架构
- 2024-07-02springboot项目无法注册到nacos-icode9专业技术文章分享
- 2024-06-26结对编程到底难不难?答案在这里
- 2024-06-19《2023版Java工程师》课程升级公告
- 2024-06-15matplotlib作图不显示3D图,怎么办?
- 2024-06-1503-Loki 日志监控
- 2024-06-1504-让LLM理解知识 -Prompt
- 2024-06-05做软件测试需要懂代码吗?
- 2024-06-0514-ShardingSphere的分布式主键实现