parallel programming

P

paytam

Hi all,
Is it possible to write parallel programming in C?
I mean for example a simple program like I have a clock on a program
that show me current time and and at the same time another job like
input data from a user.If it is possible PLZ write a simple code for me
..
 
J

Jack Klein

Hi all,
Is it possible to write parallel programming in C?

Not in standard C, no. The language defines an abstract computing
machine that does exactly one thing at a time.
I mean for example a simple program like I have a clock on a program
that show me current time and and at the same time another job like
input data from a user.If it is possible PLZ write a simple code for me

There are extensions to C, and other languages, that provide ways of
doing this, if the underlying platform provides support. But they are
not part of the C language and outside the scope of this group. You
need to ask in a group that discusses programming for your particular
compiler and operating system combination to learn about what
extensions it might offer.
 
M

Malcolm

Is it possible to write parallel programming in C?
I mean for example a simple program like I have a clock on a program
that show me current time and and at the same time another job like
input data from a user.If it is possible PLZ write a simple code for me
.
There are lots of solutions to the problem of writing parallel C code. For
example there is a language called "parallel C" with instruction like "pfor"
( a for loop which can be executed in parallel).
The one that seems to have caught on is the message passing interface, or
MPI. Superficially it looks like a familiar series of C function calls. In
fact you need a special compiler - it cannot be implemented as a normal
library.

All of them are currently off-topic. (There might be an argument for
expanding the scope of the ng to include parallel implementations, but
presently the convention is that we confine ourselves to ANSI C)
However you don't need true parallel programing to achieve parallel
execution.
For instance as long as you can call a routine called update_clock() more
frequently than once a second, the clock will appear to the user to be
ticking along in parallel.

ANSI C input functions are blocking, so if the user waits five minutes
before pressing the newline, getc() will wait for him. However there are
always extension like "kbhit" available which get round this problem,
allowing you to check for input and, if it is not present, update the clock.
 
T

Tim Prince

Malcolm said:
There are lots of solutions to the problem of writing parallel C code. For
example there is a language called "parallel C" with instruction like "pfor"
( a for loop which can be executed in parallel).
The one that seems to have caught on is the message passing interface, or
MPI. Superficially it looks like a familiar series of C function calls. In
fact you need a special compiler - it cannot be implemented as a normal
library.

That is exactly how it is implemented, even though a wrapper is supplied
for each supported compiler, and it is possible, though misguided, to
avoid the wrapper and invoke your C directly.
You may be thinking of OpenMP, which is impractical to implement without
at least a special pre-processor. There are also compilers which can
implement a limited subset of OpenMP simply by throwing a command line
switch.
The OP problem looks more like homework aimed at the beginnings of
teaching about an operating system, not what many of us think of as
parallel programming. Yes, it is possible to write an OS largely in C,
e.g. gnu/linux. Still OT, as it hasn't been done in purely standard C.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top