Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Using Java with Dual & Quad Processors.

Reply
Thread Tools

Using Java with Dual & Quad Processors.

 
 
Sanny
Guest
Posts: n/a
 
      01-10-2008
I have a function which I call using for loop. I want that when My
Java program is run on Dual Core its speed increases by twice and when
it run on Quad core its speed increase 4 time.

Here is the Code I am using.

const NUMBER=1000;
Public int int_x;
Public int[] Array1= new int[NUMBER];

init (){
for (int i=0;i<NUMBER;i++){

function_abc(i);
}
}

// function_abc returns same value for a given Value of "i".

function_abc(int i){
int_x++;
....
....
....
Array1[i]=i*5+int_x;
}

So in the end we get an Array[i] with the formula values. On a single
processor it goes through all the for loop in NUMBER times.

I want on Dual Core the Performance doubles by using Threads. So
function_abc(i); is Called in multiple threads and Speed increases X
times depending on number of X Processors the System has.

How can it be done, any idea.

So for Single Core it will have no spped increase.

For Dual Core Twice Speed

For Quad Core 4 Times speed is seen.

Bye
Sanny


 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      01-10-2008
Sanny wrote:
> I have a function which I call using for loop. I want that when My
> Java program is run on Dual Core its speed increases by twice and when
> it run on Quad core its speed increase 4 time.


Amdahl's Law precludes a full linear speed increase with more processors, but
you should be able to reach some significant fraction with careful coding.

> Here is the Code I am using.
>
> const NUMBER=1000;
> Public int int_x;
> Public int[] Array1= new int[NUMBER];


I guarantee you that you aren't using this code, at least not in Java. This
stuff will not compile.

> init (){
> for (int i=0;i<NUMBER;i++){
>
> function_abc(i);
> }
> }
>
> // function_abc returns same value for a given Value of "i".
>
> function_abc(int i){
> int_x++;
> ....
> ....
> ....
> Array1[i]=i*5+int_x;
> }
>
> So in the end we get an Array[i] with the formula values. On a single
> processor it goes through all the for loop in NUMBER times.
>
> I want on Dual Core the Performance doubles by using Threads. So
> function_abc(i); is Called in multiple threads and Speed increases X
> times depending on number of X Processors the System has.
>
> How can it be done, any idea.


I suggest that you write a full, single-core implementation and post it here
for comment. Make sure that you actually run your program, or try to. Even
if it doesn't do everything you plan, it should do something at every stage of
development. At the very least, this will give you compilable code to post to
Usenet, unlike now, or at the very, very least, compiler errors to ask about.

If you do ask about compiler errors, please post your entire short but
*complete* example with your question(s), and do literally copy and paste the
error message(s) into your post - do not paraphrase.

Any example should be an SSCCE - simple short complete compilable example (my
version of Andrew's acronym).

--
Lew
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      01-10-2008
On Thu, 10 Jan 2008 01:24:47 -0800 (PST), Sanny
<> wrote, quoted or indirectly quoted someone who
said :

>
>How can it be done, any idea.


A thread has a fairly high start up cost, so there is not much gained
to great a thread just to initialize an array. Also for threads to
work well they should not be poking at the same ram or they just trip
over each other.

So want to split your app up in ways that don't overlap, e.g.
computation and painting the GUI, or doing I/O and computing,

You might do it by splitting your data in 4 parts and turning a thread
loose on each part.

Design your app so you can vary the number of threads to optimal
performance determined by experiment.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Quad Drive Explorer Quad Drive Explorer (View 5 Drives at the same time).. scott93727@gmail.com Computer Information 0 09-25-2012 03:14 AM
How to use power of Dual/ Quad core Processors in Applet? Sanny Java 29 07-25-2007 04:18 AM
NetGear SPH200D dual Dual-mode, Cordless Phone vs Dualphone 3088 dual mode cordless phone Paul NZ Computing 0 05-08-2007 09:06 AM
2 Dual Core 3Ghz Xeon or 2 Quad Core 2.33Ghz Xeon? Adrian Windows 64bit 5 03-19-2007 07:40 PM
Support for Quad processors or two dual core opertions.. =?Utf-8?B?LS0gSmFtZXMgLS0=?= Windows 64bit 13 06-11-2005 02:02 PM



Advertisments