473,757 Members | 10,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# 3.0 adding functional suppoty and Multi core processors

I just read an overview of C# 3.0, and it occured to me that some of
these features could make it much easier to write programs that
automatically make use of multi core processors. After reading that
lambda functions are available in 3.0, I read up on the advantages of
functional programming, and one of the advantages is that tasks
performed in a functional language do not have side effects, and thus
tasks can be divided between processors easily without dealing with
concurrency as much.

What I'm wondering, if someone exprienced with functional programming
can chime in, are the added features enough to program tasks in a
purely functional manner?

I'm imagining some sort of architecture where each function call in a
task is automatically handed off to a different worker thread. As long
as we write the task in a functional manner, where there is no
dependancy on side effects, then we don't have to worry about the
locking and synchornization issues.

It's been a long time since I wrote anything in a functional
programming language, and am not deeply familier with C# 3.0, but I
wanted to post this and see what other's opinions are.

Jun 7 '06 #1
5 1816
sh******@cs.fsu .edu wrote:
I'm imagining some sort of architecture where each function call in a
task is automatically handed off to a different worker thread. As long
as we write the task in a functional manner, where there is no
dependancy on side effects, then we don't have to worry about the
locking and synchornization issues.


Simply calling each function call in a seperate worker thread won't
automatically give you benefits of a multi-core or processor system as
the calling function will need to block until the callee returns. Thus
if you're using thirty different threads but 29 of them are blocking you
really don't get any advantages.

Besides, IIRC from college, functional languages are really good at
solving certain problem sets, but for other problem sets they are
actually more complex to use.

Andrew Faust
Jun 7 '06 #2
Andrew Faust <an****@lapathy .com> wrote:
sh******@cs.fsu .edu wrote:
I'm imagining some sort of architecture where each function call in a
task is automatically handed off to a different worker thread. As long
as we write the task in a functional manner, where there is no
dependancy on side effects, then we don't have to worry about the
locking and synchornization issues.
Simply calling each function call in a seperate worker thread won't
automatically give you benefits of a multi-core or processor system as
the calling function will need to block until the callee returns.


Separating each function call into a separate thread pretty much implies
*not* blocking on the function result immediately, otherwise there'd be
no point in creating a separate thread at all. Therefore the most
sensible route is to call multiple functions one after the other, then
wait on them to return only when the return value is needed. The fact
that it's a functional approach implies that the return value is the
only side-effect anyway. Imagine code something like this:

---8<---
Active<int> first = CalcFirst();
Active<int> second = CalcSecond();
return new Active<int>(del egate { return first.Value * second.Value; });
--->8---

.... where Active<T>.Value waits for the calculation to finish, and
Active<T>'s constructor takes a delegate Evaluator that looks like:

delegate T Evaluator<T>()

.... and runs it on a background thread.

That code borrows from the "active" ideas for C++ presented by Herb
Sutter at the last PDC. I've written some ideas like this in my own
libraries. The can work well for limited scenarios - where the
calculation cost is much greater than the current overhead for handing
off to the threadpool.

If the .NET framework had efficient pipelined low-level threading
primitives, one could see this as being an efficient way to use multiple
cores, imagining that CalcFirst, CalcSecond and '*' on ints were
operations sufficiently slow to benefit from parallel calculation, which
implies extra latency for communicating the return values.
Besides, IIRC from college, functional languages are really good at
solving certain problem sets, but for other problem sets they are
actually more complex to use.


If all your data is immutable for a particular subgraph and you need to
perform calculations or copying transformations on this subgraph, a
functional approach can make life much easier and less buggy, as well as
possibly improving performance in a multi-core world. I know its helped
me in the past.

-- Barry

--
http://barrkel.blogspot.com/
Jun 7 '06 #3
Hi!
cores, imagining that CalcFirst, CalcSecond and '*' on ints were
operations sufficiently slow to benefit from parallel calculation, which
implies extra latency for communicating the return values.


Considering that the OS switches between threads about every 20ms.
It would only make sense to use multiple cores for tasks that take
longer than 20ms to compute. And that is usually a very "fat" chunk of
processing.

Regards!
Atmapuri
Jun 7 '06 #4
"Atmapuri" <di*@community. nospam> wrote:
Hi!
cores, imagining that CalcFirst, CalcSecond and '*' on ints were
operations sufficiently slow to benefit from parallel calculation, which
implies extra latency for communicating the return values.
Considering that the OS switches between threads about every 20ms.


This assumes that there are other tasks that are using 100% of every
CPU. Also, a thread's time slice ends sooner if it blocks on a
synchronization object. It only makes sense to multi-thread these
calculations if not all CPUs are being utilized to 100% anyway, which
implies that there will (probably) be an idle CPU for the task, which in
turn implies that it should take less than 20ms before the thread gets
started (a slice "timeout" will not be needed at all if a CPU is idle).
It would only make sense to use multiple cores for tasks that take
longer than 20ms to compute. And that is usually a very "fat" chunk of
processing.


I don't agree with your reasoning.

-- Barry

--
http://barrkel.blogspot.com/
Jun 7 '06 #5
Ah, I love when I hit tab and then reallize I can't tab in a text box
because it changes focus, then hit backspace and it goes back a page
and I lose everything I have written :(

In a nutshell, if you have a recursive process that uses the recursive
calls as parameters to itself like Do(Do(n+1,term) , Do(n+2,term)) then
your calls can be visuallized as a tree, and you would hand off the
right paramter to another thread, but only until you've filled all
processors. At that point there would be no more handing off, and each
thread would work it's part of the call tree using the normal call
stack process.

If a thread finished before the others, then one of the others could
hand off again at the next most convient split point.

Since we don't want to mess with threads if the recursive process isn't
going to get very deep, the programmer could specifiy conditions in an
imperetive manner such as:

DoInit(int n, int term)
{
if( (n-term) >= 100)
{
FlagUsageOfMult ithreading();
}

Do(n,term);
}

If you were processing some sort of large set of data, your condition
would be based on the number of items in the data set. Of course it's
not provable when or if something will terminate, but since you're only
concerned with identifying what is "too small" for multithreading, then
for small values or small sets of data, the programmer should be able
to make a good estimate of how many calls will be required. With that
they would estimate what the breaking point is that makes
multithreading worth it.

I suppose there has already been alot of research in these regards in
the realm of distributed computing. It seems that since the future is
going to be single user systems running multi core processors, then
there is going to be a need for easy to use techniques that allow
programmers to get the most out of these processors.

Barry Kelly wrote:
"Atmapuri" <di*@community. nospam> wrote:
Hi!
cores, imagining that CalcFirst, CalcSecond and '*' on ints were
operations sufficiently slow to benefit from parallel calculation, which
implies extra latency for communicating the return values.


Considering that the OS switches between threads about every 20ms.


This assumes that there are other tasks that are using 100% of every
CPU. Also, a thread's time slice ends sooner if it blocks on a
synchronization object. It only makes sense to multi-thread these
calculations if not all CPUs are being utilized to 100% anyway, which
implies that there will (probably) be an idle CPU for the task, which in
turn implies that it should take less than 20ms before the thread gets
started (a slice "timeout" will not be needed at all if a CPU is idle).
It would only make sense to use multiple cores for tasks that take
longer than 20ms to compute. And that is usually a very "fat" chunk of
processing.


I don't agree with your reasoning.

-- Barry

--
http://barrkel.blogspot.com/


Jun 7 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
4895
by: ajikoe | last post by:
Hello, Is anyone has experiance in running python code to run multi thread parallel in multi processor. Is it possible ? Can python manage which cpu shoud do every thread? Sincerely Yours, Pujo
2
2118
by: JohnFol | last post by:
I know Windows / SQL etc can utilise multiple processors. In the good old days of coding, you simply wrote the .EXE and Windows would run it on a single processor (or a given processor for multi-processor machines) I know also that threads exist, but am having a few problems understanding how they are split across processors so here is an easy example. I have a VB.Net written application that is processor intensive. It has not been...
2
2683
by: webwarrior | last post by:
Hi, Is there a reason why we have to pay more for licensing for a different kind of processor? Why are we not charged for the Hyperthreading on some processors also. If Oracle is really conserned about the low end business market (small and medium), then they should drop their attitude on Dual Core processors.
20
5963
by: dotyet | last post by:
Hi Everyone, It would be a real big help if anyone can shed light on whether DB2 UDB 8.2 on Solaris will make optimum use of a Sun T2000 server. The server has 1 CPU with 8 cores and each core has 4 threads (32 virtual CPUs). We are exploring this option againts an equivalent performance pSeries box. But before we delve deeper, we want some basic info on that. Any suggestions would be helpful.
60
4932
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the 'target' programming community herein) to get some community input and verify (or not) the following two statements. Few programmers (3 to7%) UNDERSTAND 'Strategic Functional Migration
3
1233
by: JDeats | last post by:
Looking to pick up a notebook and wanted query the developer community for any feedback, sorry if this is off topic. Does the Intel Core 2 Duo chip offer any advantages to .NET developers? I remember, it seems like a year or so back when the 64-bit AMD chips were still new, there was a big deal about 64-bit being supported in VS.NET 2005. I've gotten a bit behind on the CPU advancements and what 64-bit currently means to managed code.
5
1948
by: Coaster | last post by:
I am designing a process which will spawn a good number of threads and some of them will execute a c++ process which is quite memory intensive (although not multithreaded). This will run on a 2 cpu (both dual core) server. What do I need to do if anything in order to spread the workload across the cpu's / cores in order to tune it properly? I googled it and found this post but its somewhat dated and didn't know if it applied to 2.0
11
4922
by: John | last post by:
Is there a way to find the number of processors on a machine (on linux/ windows/macos/cygwin) using python code (using the same code/cross platform code)?
14
2872
tharden3
by: tharden3 | last post by:
When you get a 2.4 GHz Core Duo, are you splitting one 2.4 processor into two parts, or do you literally have two 2.4 GHz processors? Same for a Quad Core?
0
9489
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9298
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9906
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9737
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3829
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.