문제

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