What is the difference between multiprocessor programming and multicore programming?

preferably show examples in python how to write a small program for multiprogramming & multicore programming

解决方案

There is no such thing as "multiprocessor" or "multicore" programming. The distinction between "multiprocessor" and "multicore" computers is probably not relevant to you as an application programmer; it has to do with subtleties of how the cores share access to memory.

In order to take advantage of a multicore (or multiprocessor) computer, you need a program written in such a way that it can be run in parallel, and a runtime that will allow the program to actually be executed in parallel on multiple cores (and operating system, although any operating system you can run on your PC will do this). This is really parallel programming, although there are different approaches to parallel programming. The ones that are relevant to Python are multiprocessing and multithreading.

In languages like C, C++, Java, and C#, you can write parallel programs by executing multiple threads. The global interpreter lock in the CPython and PyPy runtimes preclude this option; but only for those runtimes. (In my personal opinion, multithreading is dangerous and tricky and it is generally a good thing that Python encourages you not to consider it as a way to get a performance advantage.)

If you want to write a parallel program which can run on multiple cores in Python, you have a few different options:

Write a multithreaded program using the threading module and run it in the IronPython or Jython runtime.

Use the processing module, (now included in Python 2.6 as the multiprocessing module), to run your code in multiple processes at once.

Use the subprocess module to run multiple python interpreters and communicate between them.

Use Twisted and Ampoule. This has the advantage of not just running your code across different processes, but (if you don't share access to things like files) potentially across different computers as well.

No matter which of these options you choose, you will need to understand how to split the work that your program is doing up into chunks that make sense to separate. Since I'm not sure what kind of programs you are thinking of writing, it would be difficult to provide a useful example.

python多核多线程编程_python是否支持多处理器/多核编程?相关推荐

  1. python异步多线程框架_Python网络编程中的服务器架构(负载均衡、单线程、多线程和同步、异步等)。...

    这篇文章主要介绍服务器架构. 网络服务需要面对两个挑战.第一个问题是核心挑战,要编写出能够正确处理请求并构造合适响应的代码. 第二个挑战是如何将网络代码部署到随系统自动启动的Windows服务或者是U ...

  2. python多核运行程序_python单进程能否利用多核cpu的测试结论

    在很早的时候,就听网上的文章说: python有GIL,所以在单进程内,即使使用多线程也无法利用到多核的优势,同一时刻,python的字节码只会运行在一个cpu上. 以前也是奉为真理,直到今天在对自己 ...

  3. python 为什么没有重载_python是否支持重载

    在一些静态语言中,大都存在有一个重载的概念.这是在OOP(面对对象编程)中一个必不可少的一个行为. 所谓重载,就是多个相同函数名的函数,根据传入的参数个数,参数类型而执行不同的功能.所以函数重载实质上 ...

  4. python 接口编程_Python 中的面向接口编程

    前言 "面向接口编程"写 Java 的朋友耳朵已经可以听出干茧了吧,当然这个思想在 Java 中非常重要,甚至几乎所有的编程语言都需要,毕竟程序具有良好的扩展性.维护性谁都不能拒绝 ...

  5. python接口编程_Python 中的面向接口编程

    前言 "面向接口编程"写 Java 的朋友耳朵已经可以听出干茧了吧,当然这个思想在 Java 中非常重要,甚至几乎所有的编程语言都需要,毕竟程序具有良好的扩展性.维护性谁都不能拒绝 ...

  6. python内核多线程库_python / numpy中的多线程blas

    我已经将其发布在另一个线程中,但我认为它更适合于此: 更新(30.07.2014): 我在新的HPC上重新运行基准测试.硬件和软件堆栈都与原始答案中的设置有所不同. 我将结果放在Google电子表格中 ...

  7. python get 下载 目录_python实现支持目录FTP上传下载文件的方法

    本文实例讲述了python实现支持目录FTP上传下载文件的方法.分享给大家供大家参考.具体如下: 该程序支持ftp上传下载文件和目录.适用于windows和linux平台. #!/usr/bin/en ...

  8. python循环五要素_python常见单词在手,编程入门不愁

    点击蓝字"python教程"关注我们哟! 前言: 人工智能时代,python编程语言站在风口起飞,2018年7月的世界编程语言排行榜跃居于编程语言前三,2018年的IEEE顶级编程 ...

  9. python修饰器原理_Python修饰器的函数式编程

    Python的修饰器的英文名叫Decorator,当你看到这个英文名的时候,你可能会把其跟Design Pattern里的Decorator搞混了,其实这是完全不同的两个东西.虽然好像,他们要干的事都 ...

最新文章

  1. RuntimeError: Bool type is not supported by dlpack
  2. VS配合VSS时,编译报错:未能向文件“....csproj.FileListAbsolute.txt”写入命令行,对路径的访问被拒绝。...
  3. 输入流IS和输出流OS学习总结
  4. Linux 多线程应用中如何编写安全的信号处理函数
  5. 不合群的人,经常习惯一个人独来独往,这样的人有出息吗?
  6. spring官方文档列表
  7. Springboot+vue项目酒店民宿管理系统
  8. abaqus 输出TSAIW和一些Load Surface Traction的细节
  9. Matlab线性规划求解
  10. 如何实现数据持久性保障机制
  11. ATLAS/ICESAT-2 NASA 数据产品详细介绍及相关说明文档
  12. 【数据集】各类绝缘子、鸟巢及防震锤数据集汇总
  13. 微信图文消息中如何使用svg图片
  14. 7. MyBatis多表查询 - 一对一 - 一对多 - 多对多
  15. 2022年互联网大厂的中秋仪式感
  16. SDOI2014 Round1 day2
  17. ZOJ 3447 Doraemon's Number Game(优先队列+高精度运算)
  18. 直播网站源码实现IM即时聊天
  19. u盘锁计算机,简单几步将U盘打造成电脑登录“密码锁”,不插入就别打开!
  20. 全新【Photoshop 2022 for mac】中文版发布下载 支持M1 M1X M2处理器 详细安装教程

热门文章

  1. week04_python函数返回值、作用域
  2. html5知识点:CSS3新增选择器
  3. Hadoop源码分类概要整理
  4. 《Jersey用户指南》翻译邀请
  5. 搭建Python+Eclipse开发环境
  6. java处理高并发高负载类网站的优化方法
  7. 详解C#break ,continue, return
  8. C#程序只允许运行一个实例的解决方案
  9. ElasticSearch入门 :Windows下安装ElasticSearch
  10. VS一直停留在“正在还原nuget程序包”