I'm playing a bit with parallel programming in C; Hence whatever solution I see in the articles I'm reading are built on top of Threads or stuff like OpenMP, MPI, Select on Windows or Fork on *nix; I got the following questions:

  • Can a single process go-parallel on a single thread and without Forking itself?

  • Are there any other ways of writing parallel code, but with very basic building blocks that are available in C? Something that could be done by manually moving bits around, purely in C built-in functions -- not using a high-level library that makes use of operating system features?

Also the purpose of the question is to get a better understanding of how parallel programming works in a close-to-metal world. I don't have any interest to do micro-optimizations or reinventing the libraries.

Update

I'm basically thinking of writing Callback functions and let them get called when an Event happened; But I'm not sure if it will make it parallel or not.

有帮助吗?

解决方案 2

Can a single process go-parallel on a single thread and without Forking itself?

That is up to the compiler. The compiler is free to implement instructions between sequence points any way it wants, although most compilers don't parallellize across multiple cores in single-threaded programs.

Example: Compilers for vector processors (like the Cray supercomputers) or for GPUs (graphics cards) use unrolling to parallellize loops.

其他提示

  1. Can a single process go-parallel on a single thread and without Forking itself? — Nope.
  2. Are there any other ways of writing parallel code, but with very basic building blocks that are available in C? — Nope.
  3. the purpose of the question is to get a better understanding of how parallel programming works in a close-to-metal world — close-to-metal parallelism requires assembly language and likely a bare metal (no OS) environment.
  4. I'm basically thinking of writing Callback functions and let them get called when an Event happened; But I'm not sure if it will make it parallel or not — this by itself does not imply parallelism.
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top