Behaviour of thread in multicore processor

hiii
i want to know how thread behave in the multicore processor.
wt i know is that at a time only one thread is running in case of single processor.
but wt happen if i hv multicore processor means can 2 threads run at a time in multicore proccessor.
correct me if i m wrong in case of single processor.
thanks

GouravBansal wrote:
if i am writing a program on a single core machine.
And then running on multicore machine. Is it show me any strange behaviour or any error in any case?
or it works same as on single core machine??Others have mentioned some problems that could occur if you test your code on a single-core machine. However, to your question of writing the code on a single-core and running on a multi-core (or vice versa), it makes no difference. Java compilers produce the same bytecode regardless of whether you're compiling on a single- or mult-core machine. The hotspot JVM might make different optimizations on a multi-core or multi-CPU box, but that has nothing to do with where you wrote or compiled your code.

Similar Messages

  • Programming for Multicore processors

    I am working on a project where the software developers wrote code for an old Sun server that has been replaced by T5220s. My understanding is that these are multicore processor computers that could offer performance benefits if the code takes advantage of the hardware. The developers seem to feel that the code just needs to be recompiled and that Java will take care of everything at the JVM level. Are there any guidelines or articles discussing Java-specific improvements for multicore devices, hyperthreading, etc. Thanks for your help.

    tschodt wrote:
    sharkura wrote:
    Not to mention that the original problem may not be amenable to a parallel solution.There was no original problem as such, OP is just asking for confirmation.
    mijujoel wrote:
    ... the software developers wrote code for an old Sun server that has been replaced by T5220s.
    Actually, though he may have been asking for confirmation that the JVM handles multiprocessors, there is an original problem.
    mijujoel wrote:
    ... the software developers wrote code for an old Sun server that has been replaced by T5220s.
    ... these are multicore processor computers that could offer performance benefits if the code takes advantage of the hardwareAnd, regardless of what the answer is to the question of whether the JVM handles multiple processors, the truth is that the original problem may not be parallelizable, even if they decide to rewrite the code. I would surely want to answer that question before spending resources attempting to convert this to a multi-threaded app.
    Of course, I realize that there are almost always components of a complex application that can be run in their own threads. Still, measure twice, cut once.
    ¦ {Þ                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • BSOD-Problem ha20x22k.sys X-Fi WinXP SP3 multicore-processor

    Hi @all,
    I already read around this forum & know that the bluescreens in connection with ha20x22k.sys only happen on WinXP SP3 machines with multicore processors. There seem to be a beta driver XFTI_PCDRVBETA_2_7_0005.zip that fixes this issue. There are several postings about it here in this forum and Google finds more elsewhere.
    Only there is no download link.
    Where can I get XFTI_PCDRVBETA_2_7_0005.zip?
    Sincerely - Harry Zingel - www.zingel.de

    Hi!
    I had similar problems with a older Creative Cards. This ist PCI-IRQ Routing problem most caused by a Bios that is not 00% ACPI compatible, even if the manufracturer say it is 00% compatible.
    I solved this with a Bios upgrade or before is did the Bios upgrade i changed the ACPI kernel to a MPS kernel (i wont suggest that because if something goes wrong, it is not easy to repair the OS and needs much OS-internal-related knowledge to do this).

  • JVM's suport for multicore processors and multiple processor systems

    Hi all,
    Do you have any concrete information about Sun Hot JVM 1.5's support for multi-core processors and also its support for multi processor systems. I ask this because i am looking at deploying a multi threaded application written in Java 5 and want to know the best CPU arrangement for optimal performance.
    Does JVM run itself on multiple CPUs?
    Does JVM run native threads on multiple CPUs ? at the same time.
    Is there a place where i can find out the exact behavior of the JVM in sus environments ?
    Thanks.

    Hi,
    Sun's JVM runs very well on multi-thread/core/chip systems and provides several mechanisms to scale well in such environments (for example Thread Local Allocation Buffers (TLABs), parallel gargabe collection threads etc.). Java threads are 1:1 mapped to operating system threads. There are lots of options that allow you to configure the JVM wrt number of gc threads and so on, although the defaults should in most cases work well. There is a lot information available at http://java.sun.com/docs/performance/index.html and some (quite outdated) information about threading at http://java.sun.com/docs/hotspot/threads/threads.html.
    Nick.

  • A strange behaviour throwing Threads via anonymous class technique

    Hi friends!
    I've noted a strange behaviour executing the next code:
    public class ResolAnonimes
         private int value;
         public ResolAnonimes(int value)
              this.value = value;
         public ResolAnonimes myMethod(int nThreads)
              final ResolAnonimes a = this;
              int nThreadsFor = nThreads - 1;
              for( int i=0; i < nThreadsFor; i++)
                   new Thread(){
                        public void run()
                                System.out.println(Thread.currentThread().getName() + " has begun processing");
                                     doSomethingWith(a);
                                System.out.println(Thread.currentThread().getName() + " has finished processing");
                   }.start();
                   this.value++;
              }//for loop
              return a;
         public static void doSomethingWith(ResolAnonimes a)
              System.out.println(a.value);
         public static void main(String Args[])
              ResolAnonimes first = new ResolAnonimes(1);
              ResolAnonimes result = first.myMethod(5);
    }When I execute it, that's the output I get:
    Thread-0 has begun processing
    2
    Thread-0 has finished processing
    Thread-0 has begun processing
    3
    Thread-0 has finished processing
    Thread-0 has begun processing
    4
    Thread-0 has finished processing
    Thread-0 has begun processing
    5
    Thread-0 has finished processingWhere's the "1" printed? It doesn't appear! It seems it has thrown only 4 threads, not 5.
    Am I doing anything wrong? Is it a bug?
    Can you help me, please?
    Thank you in advance.

    Oh I'm sorry. I was changing the code because of privacy rerasons and I finally didn't type what I want.
    Consider an array which all cells must be typed with the array lentgh. Moreover, the work is distributed by some threads.
    I'm refering to something like this:
    import java.util.Random;
    import java.util.LinkedList;
    public class MyArray
         private static int initialRow = 0;
         private static int lastRow = 0;
         private int[] vector;
         public MyArray(int size)
              vector = new int[size];
         public static boolean correctIndex(MyArray a )
              for(int i = 0; i< a.vector.length; i++)
                   if(a.vector[i] != a.vector.length)
                        return false;
              return true;
         public String toString()
              String s ="";
              for(int i=0; i < this.vector.length; i++)
                   s += this.vector[i] + " ";
              return s;
         public MyArray  operationWith(int nThreads)
              MyArray a = this;
              MyArray result = null;
              final Contenidor ctros = new Contenidor(new LinkedList());
              result = a.putTheIndexValue(nThreads, ctros);
              Thread consumerThread = new Thread( new Consumer( ctros, nThreads));
              consumerThread.start();
              try
                   consumerThread.join();
              catch(InterruptedException ie){}
              return result;
         public MyArray putTheIndexValue(int nThreads, Contenidor ctros) //Este metode encara es experimental
              final MyArray a = this;
              final MyArray result = new MyArray( a.vector.length);
              final Contenidor ctrosR = ctros;
              for(int i = 0; i < result.vector.length; i++)
                        result.vector= 0;
              int incRows = a.vector.length / nThreads - 1;
              initialRow = 0;
              lastRow= incRows;
              int nFilsFor = nThreads - 1;
              Thread[] vectorFils = new Thread[nThreads];
              for( int i=0; i < nFilsFor; i++)
                   /*vectorFils[i] = */ new Thread()
                                                 public void run()
                                                      System.out.println(Thread.currentThread().getName() + " has begun processing");
                                                      MyArray.putTheIndexValue( a, initialRow, lastRow);
                                                      System.out.println(Thread.currentThread().getName() + " has finished processing");
                                                      String s = Thread.currentThread().getName();
                                                      ctrosR.put(s);                         
                   vectorFils[i]*/.start();
                   initialRow = initialRow + 1;
                   lastRow = initialRow + incRows;
              new Thread()
                   public void run()
                        System.out.println(Thread.currentThread().getName() + " has begun processing");
                        MyArray.putTheIndexValue( a, initialRow, a.vector.length - 1);
                        System.out.println(Thread.currentThread().getName() + " has finished processing");
                        String s = Thread.currentThread().getName();
                        ctrosR.put(s);                         
                   vectorFils[i]*/.start();
              return result;
         public static void putTheIndexValue( MyArray a, int initialRow, int lastRow)
              for(int i = initialRow; i <= lastRow; i++)
                   a.vector[i] = a.vector.length;
    public class Interface
         public static void main(String Args[])
              int nThreads = 2;
              int arraySize = 5;
              MyArray ma = new MyArray(arraySize);
              MyArray result = ma.operationWith(nThreads);
              if(MyArray.correctIndex(result))
                   System.out.println("The operation has been done correctly");
              else
                   System.out.println("THE OPERATION HAS NOT BEEN CORRECTLY!");
              System.out.println(ma.toString());
    public class Consumer implements Runnable
         private Contenidor ctros;
         private int nFils;
         public Consumer(Contenidor ctros, int nFils)
              this.ctros = ctros;
              this.nFils = nFils;
         public void run()
              System.out.println(Thread.currentThread().getName() + "is waiting the total process to be finished");
              for(int i = 0; i< nFils; i++)
                      System.out.println( Thread.currentThread() + " is waiting a thread to give me its chunk");
                      String s = ctros.get();
                      System.out.println( Thread.currentThread() + ":  " + s + " has already given me its chunk");
                 System.out.println(Thread.currentThread().getName() + "says all threads have finished");
    import java.util.Queue;
    import java.util.LinkedList;
    public class Contenidor
        private int nDadesNoves;
        private Queue contenidor;
        public Contenidor(Queue contenidor)
            this.contenidor = contenidor;
            this.nDadesNoves = 0;
        public synchronized String get()
            while(nDadesNoves < 1)
                try
                    wait();
                catch(InterruptedException ie){}
            nDadesNoves--;
            notifyAll();
            return (String)contenidor.poll();
        public synchronized void put(String s)
            contenidor.offer(s);
            nDadesNoves++;
            notifyAll();
    }The output I get sometimes is:
    THE OPERATION HAS NOT BEEN CORRECTLY!
    5 5 5 5 5And I get also sometimes that:
    THE OPERATION HAS NOT BEEN CORRECTLY!
    0 5 5 5 5That's what I wanted to refer last post. I think I'm doing a correct synchronization. Am I wrong?
    I don't understand that behaviour.
    Anyone can help me, please?
    Thank you in advance.

  • Multiple threads on multiple processors

    Hi
    I am trying to write some code which will actually need to run on a multi processor machine with 14 CPUs
    I do not want to use RMI so I am left with the option of Threads
    As far as i know on a single processor the threads are time sliced and give you a feeling of parallelism and hence this is virtual parallelism, but what about a multiprocesor machine
    Is it that each of the thread gets its own CPU and if it is so is this a rule or is it dependent on the OS and the JVM. Is there any way I can verify if the threads are actually running on differnt CPUs
    any help on this is highly appreciated
    regards
    avinash

    This all rather depends on the way your application is designed and implemented.
    In theory, a VM running on a multi-processor machine can have as many active threads running in parallel as there are CPUs.
    However, if your application runs in a single Thread then this can only run on one CPU, regardless of how many are available.
    The system internal Threads, such as the GC thread can and do run where they are told to, especially if you can make use of concurrent GCing in jdk1.4.
    You are going to have to look at the way you are solving the tasks at hand in your application.
    Partitioning the problem so that you can subdivide things such that each partial problem can be solved in parallel, thus taking advantage of multiprocessor machines can be a difficult (in some cases impossible) task. If your application is meant to solve such a problem then you are in luck.
    Example of an easily partitioned problem. Ray Tracing - you can divide up the problem area into sub-parts of the 3D model you want to render and each sub-part can be solved in parallel.
    In any event, an application that runs in a single thread is not going to run any faster on a multiprocessor machine.

  • Multi-Thread - Utilizing Multicores

    Does Crystal Report XI do multi-threading?  I upgrading computers at work and I'm trying to get as much speed out ofthe computers as possible.  The main mfg computer using Crystal Reports Daily and I'm looking at upgrading it to Quad Core 2.66Ghz.  But I have found out that many of the software packages we use are unable to utilize the core.
    Will Crystal Reports?

    Thanks,
    I use a piece of software called Planit Solid which uses Crystal Reprts to create is cut sheets with in Solid.  So I'm limited.

  • Multicore Processor Dividing - Best Practices or Advice?

    I am making a dedicated Cluster with QAdministrator that uses different models of Macs.
    01 - Xserve with 4 cores (dual dual cores). (2i)
    02 - Octocore MacPro 01 (4i)
    03 - Octocore MacPro 02(4i)
    04 - Intel Core Duo MacBook Pro (1i)
    05 - G5 Dual Core (1i)
    06 - Intel Core Duo Mac Mini (1i)
    In the Apple QMaster Preferences, you can click on the Compressor Service and choose how many "Instances" to create for each computer.
    I've been making the Octocore MacPros into 4 instances. And the Xserve Quad Core into 2 instances and everything else into 1 instance.
    It is my understanding that Compressor looks at how many available instances are present and then divides the footage into 2 times that many Segments.
    So counting above, I am getting 13 individual processing instances, so Compressor is breaking my footage up into 26 segments.
    If every computer was 1 instance, I would have 6 instances and 12 larger pieces.
    Is it better for the MacPros to use all 8 processors on 1 bigger chunk of video, or not? Is it better to break up the 8 cores so they are more balanced with the other processors?
    Any thoughts and solid experience would be useful for me to hear.
    Thank you. Jesus.

    The easiest thing to do is to just install the latest into a clean directoryI believe different versions of jdk install into their own separate directory by default. All one needs to do is recreate the symbolic links that point to the version they want to use. The java install documentation has the details.

  • Application freezing and recovering & Strange behaviour in Thread Dump & GC

    Hi All,
    I am facing a problem in my SWINGS application. The application is a real time data streaming application its working in TCP/IP sockets, which is reading and writing data in string format. I noticed that the data streaming getting freeze sometimes and it recovers after a few minutes. To find out why it is behaving like that i took the Thread Dump and Garbage Collection Trace of the application and found some thing strange. Find below the line taken from the Thread Dump, the third line in the log below shows that the time have jumped backwards, I don't know why that happened.
    2009-03-12 17:07:48
    Full thread dump Java HotSpot(TM) Client VM (1.6.0-b105 mixed mode, sharing):
    2009-03-12 17:07:57
    Full thread dump Java HotSpot(TM) Client VM (1.6.0-b105 mixed mode, sharing):
    *2009-03-12 17:04:08*
    Full thread dump Java HotSpot(TM) Client VM (1.6.0-b105 mixed mode, sharing):
    2009-03-12 17:04:15
    Full thread dump Java HotSpot(TM) Client VM (1.6.0-b105 mixed mode, sharing):
    2009-03-12 17:04:28
    Full thread dump Java HotSpot(TM) Client VM (1.6.0-b105 mixed mode, sharing):
    Almost during the same time in Garbage Collector log, normally the garbage collector was running multiple times a second and during that time the frequency of garbage collection reduced. please find the details below
    3682.686: [GC 28265K->25644K(41312K), 0.0009666 secs]
    3682.731: [GC 28268K->25645K(41312K), 0.0009825 secs]
    3682.817: [GC 28269K->25647K(41312K), 0.0010381 secs]
    3682.934: [GC 28271K->25649K(41312K), 0.0009364 secs]
    3682.943: [GC 28273K->25649K(41312K), 0.0008954 secs]
    3682.985: [GC 28273K->25650K(41312K), 0.0008845 secs]
    3683.037: [GC 28274K->25651K(41312K), 0.0008747 secs]
    3683.199: [GC 28275K->25651K(41312K), 0.0010448 secs]
    *3698.250: [GC 28275K->25728K(41312K), 0.0009655 secs]*
    *3720.655: [GC 28352K->25867K(41312K), 0.0010588 secs]*
    *3743.011: [GC 28491K->26000K(41312K), 0.0015047 secs]*
    *3765.935: [GC 28624K->26130K(41312K), 0.0010180 secs]*
    *3788.487: [GC 28754K->26260K(41312K), 0.0011328 secs]*
    *3810.348: [GC 28884K->26402K(41312K), 0.0010091 secs]*
    *3832.596: [GC 29026K->26523K(41312K), 0.0010373 secs]*
    *3855.048: [GC 29147K->26652K(41312K), 0.0010029 secs]*
    *3877.230: [GC 29276K->26795K(41312K), 0.0010387 secs]*
    *3899.420: [GC 29419K->26915K(41312K), 0.0009959 secs]*
    3922.146: [GC 29539K->27042K(41312K), 0.0010088 secs]
    3922.201: [GC 29666K->27043K(41312K), 0.0010297 secs]
    3922.231: [GC 29667K->27046K(41312K), 0.0008521 secs]
    3922.260: [GC 29670K->27048K(41312K), 0.0009208 secs]
    3922.269: [GC 29672K->27048K(41312K), 0.0009831 secs]
    3922.298: [GC 29672K->27049K(41312K), 0.0008867 secs]
    3922.308: [GC 29673K->27050K(41312K), 0.0009264 secs]
    can any one please explain whats happening, I am getting no clue from these
    Thanks in Advance
    Rajin Das
    Edited by: rajindas on Mar 16, 2009 6:40 PM

    Have you used any profilers to analyze the logs? It is very difficult to read it just like that.
    I use IBM Monitoring and Diagnostic Tools for Java™. I think it does support Sun and IBM JVMs. Try out and let me know how it goes.

  • Multi-processor Multi-Threaded deadlock

    Hi all-
    I've posted this over at jGuru.com and haven't come up with an effective solution but I wanted to try here before I reported this as a bug. This deals with kicking off many threads at once (such as might happen when requests are coming in over a socket).
    I'm looking for a way to find out when all of my threads have finished processing. I have several different implementations that work on a single processor machine:
    inst is an array of 1000+ threads. The type of inst is a class that extends threads (and thus implements the runable interface).
    for (i = 0;i<Count;i++)
    inst[ i ].start()
    for (i = 0;i<Count;i++)
    inst[ i ].join();
    however this never terminates on a multiprocessor machine. I've also tried an isAlive loop instead of join that waits until all threads have terminated until it goes on. Again, this works on the single processor but not the multi-processor machine. Additionally someone suggested a solution with a third "counter" class that is synchronized and decremented in each thread as processing finishes, then a notifyAll is called. The main thread is waiting after it starts all the threads, wakes up to check if the count is zero, and if it's not it goes back to sleep. Again this will work on the single processor but not the multi-processor.
    The thread itself ends up doing a JNI call which in turn calls another DLL which I just finished making thread safe (this has been tested via C programs). The procedures are mathematically intensive but calculation time is around half a second on a P3 800Mhz.
    Any help on this is greatly appreciated. My next step will likely be tearing down the application to exclude the calculating part just to test the JVM behavior. Is there a spec with the JVM behavior on a multi processor machine, I haven't seen one and it's hard to know what to expect from join() (joining across to processors seems like wierd concept), getCurrentThread() (since 2+ threads are running at the same time), etc.

    My next step will likely be tearing down the application to
    exclude the calculating part just to test the JVM behavior.Sounds like a really good idea.
    Is there a spec with the JVM behavior on a multi processor machine, The behaviour of threads is defined in the specs.
    You might want to check the bug database also. There are bug fixes for various versions of java.

  • Excel 2010 Multicore capabilities

    I bought Office 2010 x64 bit especially to get Excel 2010 as the advertisments stated it was supposed to be able to handle large data sets more effectively. However processing large data sets it is struggling a lot more than the BETA (x32) version was (I
    realise x64 bit does not imply it is multicore). In some cases it takes hours to simply delete large numbers of merged cells.
    Looking at my task manager whilst it is performing these tasks and it appears Excel is only using 25% of my Quad processor i.e. 1 core. I spoke to Microsofts incredibly frustrating customer 'care' centre in India and was read an extract from the microsofts
    website that stated it does use multicore processors (not useful in the slightest). However after numerous follow up calls and having a member of staff remotly control my pc he told me that it only ustilises multicores when opening and closing documents. It
    cannot utilise all the cores for data manipulation.
    Can anyone confirm that this is the case? There is another thread on this forum 'multicore multithread processor compatibility' which states Office 2010 can utilise all the cores available. However if it is only in opening and closing documents then I feel
    Microsofts claims are somewhat misleading.

    Hello,
    Office 2010 x64 talks to overcoming memory limitations rather than changing the way it interacts with the processor.  Check out these 2 links along with the discussions that follow:
    http://blogs.msdn.com/b/excel/archive/2009/08/28/excel-2010-now-with-more-bits.aspx
    http://blogs.technet.com/b/office2010/archive/2010/02/23/understanding-64-bit-office.aspx
    You can play around with the processor settings in Advanced Options to see if it improves the processing performance.
    Best Regards,
    Chad
    Chad Mathiason

  • Performance by multicore/multiprocessor cluster

    what changes can be done to take best advantage of new increased number of multicore/processor for a very heavy traffic web site (sunone servers).

    To get full potential of mulitcore/multiprocessores, configure optimum number of threads for app server. Set number of threads more than number of processors if app server makes remote invocations or database calls that takes a long time to return. Configure number of threads equal to processors if maximum amount of computation occurs at app server.
    Also take into account cost of EJB passivation, HttpSession size, context switching, DB pool, jammed transactions, singletons etc.
    See limitations of different middleware/JVM/OS/hardware in grid of clusters

  • Multicore+java? Plz help..Thank You !

    Hi Friends,
    I have my first project review before the end of this month.I have problem in choosing the topic for my project.I am mostly interested in java,but my guide wants me to do the project in multicore.
    i need guidance on this.Please tell me some AIEE,ACE paper or other Research papers,which have to do with both java and multicore---I mean doing something in multicore with java.I Really need help.I tried myself to find such papers in AIEE and ACM but couldn't able to find one.so please help me.
    Thank You!

    First I'd like to apologize for being pissy earlier. I find it discouraging when I see people embarking on projects that have very little to not merit. Also this discussion has been had before and I dunno... Mostly though I had just come from a bad meeting and was in a bad mood and that really didn't help.
    Now on to the constructive bits.
    The two newish processor advances that people like to talk about are hyperthreading and multicore. As discussed previously these two are not related (although in marketing materials they often are which leads to some confusion). I do think though that some understanding of both can clear up some of other doubts people have regarding how "good" Java will be with these technologies.
    Hyperthreading
    Personally I think this one is very cool. The best way I can think to describe it is that it is like a hotspot optimizing compiler for the processor.
    What happens with hyperthreading is that the processor has more stuff on the go. The basic idea is this. In a normal processor you might have (simplified greatly here) the following steps to execute an instruction)
    1 Bits come in -> 2 bits are put into proper places -> 3 execution (the magic step -> 4 bits are put into proper places to go -> 5 bits go out
    Again simplfied but to get the idea. Each step takes a cycle of processor time to do it. In a non hyperthreading model each execution therefore takes 5 cycles. In hyperthreading it loads things up so that different instructions are at different life cycles in the processor at the same time. So maybe you have instructions at steps 1,3 and 5 all at the same time.
    This means that in theory things can go much faster. It's also interesting to note though that hyperthreading falls apart with code that has been prematurely optimized for a processor that didn't support hyperthreading. For example if the code tries to force things into processor registers.
    Multicore
    As mentioned multicore is just putting two or more core processing units on one die. This means actual parallel execution can happen.
    This is pretty simple. So what do you need in Java to take advantage of this? Well for starters you need multithreaded code. If your program has only one thread then it won't matter one bit.
    Beyond that? It's a combination of the VM and OS yes. There are already computers that have multiple processors of course so there is already existing VM's and OS's that can take advantage of this. There are a number of configuration options for Sun VM's to fiddle with how code should work on such systems.
    Perhaps surprisingly, or perhaps not, programs with multiple threads are often better off on one processor than multiple. Depends on load of course but you have to think of steps like synchronization. There is more complexity synchronizing across multiple processors than there is multiple threads on one processor. (Note not more complexity in your code but more complexity in how it is implemented by the VM and/or OS)
    Summary
    Both of these processor advancements mean good things for Java IMO. Hyperthreading in particular lends itself well to development in a language where runtime optimizations are performed. Why? Because in Java it is prefferred to gain performance by good design rather than resorting to hackery to squeeze performance from the processor directly.
    As systems grow more complex it is less and less likely that a specfic program can best judge how to tune it's own environment. Better to let a VM and/or OS and/or hardware to handle the optimization at runtime because it has the full picture of what is going on.
    It's like the same reason you really shouldn't call gc in your Java program. The VM knows at runtime far better than you at pre-compile time when it is a good idea to run a garbage collection.
    For multicore the same basic rules apply. Write good and well designed Java code and use existing and well established frameworks and it will work well on a multicore system. Write single threaded GUI apps or threading programs that have a tendency to deadlock and the outcome of multicore will be no better performance and possibly bugs that display themseleves with greater frequency.
    Further Resources
    http://blogs.sun.com/jag/entry/mpi_meets_multicore
    http://en.wikipedia.org/wiki/Hyper-threading
    http://en.wikipedia.org/wiki/Dual-core

  • Problem with dual core processors: 50% ressources are not used.

    Hello all,
    I have noticed, that the java app cannot get normally more than 50% of the system ressources. I use different threads in my application, but the app still does't achieve 100% of system power. Max 50-60%.
    If I run two processes, I get 100%, but I can't share memory space between this two process. Or I can?
    What is the best way to write an application, that can use 100%, in other words, full power of dual core processors.
    Thanks in advance.

    Try thread.setPriority() method. I am making guess
    and any comments
    from experts on this method will be highly
    acknowledged.Yeah. Don't do that, it's a bad idea.
    Back to the original post, there are two reasons this can be happening.
    1) Your code is not efficient multi-threading wise. If you are for example running two thread that are in theory parallel but in actual fact provide linear execution so that one is almost blocked by the other then multiple threads and multiple cores will underutilized. It's hard to speculate further on this without seeing your code.
    2) The OS. First of all there is the issue of how the oS shares up the processor between processes. This varies and may or may not be configurable. The bottom line on this point is that your OS may be capping the utilization of the processor by process. Again there's not enough information give by you to expand on this point. The second OS issue regards how the OS deals with multi-core. Just because you have a multicore processor does not mean that your OS automatically can take advantage of it.

  • Are AS3 timers make use of multi processor cores?

    Can anyone tell if a Timer in AS3 will force Flash player to create a new Thread internally and so make use of another processor core on a multicore processor?
    To Bernd: I am asking because onFrame I can just blit the prepared in a timer handler function frame. I mean to create a timer running each 1ms and call the emulator code there and only show generated pixels in the ON_ENTER_FRAME handler function. In that way, theoretically, the emulator will use in best case a whole CPU-core. This will most probably not reach the desired performance anyway, but is still an improvement. Still, as I mentioned in my earlier posts, Adobe should think of speeding up the AVM. It is still generally 4-5 slower than Java when using Alchemy. Man, there must be a way to speed up the AVM, or?
    For those interested what I am implementing, look at:
    Sega emulated games in flash 
    If moderators think that this link is in some way an advertisement and harms the rules of this forum, please feel free to remove it. I will not be offended at all.

    Hello Boris,
    thanks for taking the time and explaining why your project needs 60 fps. If I understand you correctly those 60 fps are necessary to maintain full audio samples rate. You said your emulator collects sound samples at the frame rate and the reduced sampling rate of 24/60 results in "choppy sound". Are there any other reasons why 60 fps are necessary? The video seems smooth.
    That "choppy sound" was exactly what I was hearing when you sent me the source code of your project. But did you notice that I "solved" (read: "hacked around") the choppy sound problem even at those bad sampling rates? First off, I am not arguing with you about whether you need 60fps, or not. You convinced me that you do need 60fps. I still want to help you solve your problem (it might take a while until you get a FlashPlayer that delivers the performance you need).
    But maybe it is a good time to step back for a moment and share some of the results of your and my performance improvements to your project first. (Please correct me if my numbers are incorrect, or if you disagree with my statements):
    1) Embedding the resources instead of using the URLLoader.
    Your version uses URLLoader in order to load game resources. Embedding the resources instead does not increase the performance. But I find it more elegant and easier to use. Here is how I did it:
    [Embed(source="RESOURCES.BIN", mimeType="application/octet-stream")]
    private var EmbeddedBIN:Class;
    const rom : ByteArray = new EmbeddedBIN;
    2) Sharing ByteArrays between C code and AS code.
    I noticed that your code copied a lot of bytes between video and audio memory buffers on the C side into a ByteArray that you needed in order to call AS functions. I suggested using a technique for sharing ByteArrays between C code and AS code, which I will explain in a separate post.
    The results of this performance optimization were mildly disappointing: the frame rate only notched up by 1-2 fps.
    3) Optimized switch/case for op table calls
    Your C code used a big function table that allows you to map op codes to functions. I wrote a script that converted that function table to a huge switch/case statement that is equivalent to your function table. This performance optimization was a winner. You got an improvement of 30% in performance. I believe the frame rate suddenly jumped to 25fps, which means that you roughly gained 6fps. I talked with Scott (Petersen, the inventor of Alchemy) and he said that function calls in general and function tables are expensive. This may be a weakness within the Alchemy glue code, or in ActionScript. You can work around that weakness by replacing function calls and function tables with switch/case statements.
    4) Using inline assembler.
    I replaced the MemUser class with an inline assembler version  as I proposed in this post:
    http://forums.adobe.com/thread/660099?tstart=0
    The results were disappointing, there was no noticeable performance gain.
    Now, let me return to my choppy sound hack I mentioned earlier. This is were we enter my "not so perfect world"...
    In order to play custom sound you usually create a sound object and add an EventListener for SampleDataEvent.SAMPLE_DATA:
    _sound = new Sound();
    _sound.addEventListener( SampleDataEvent.SAMPLE_DATA, sampleDataHandler );
    The Flash Player then calls your sampleDataHandler function for retrieving audio samples. The frequency of those requests does not necessarily match with the frequency onFrameEnter is being called. Unfortunately your architecture only gets "tickled" by onFrameEnter, which is currently only being called 25fps. This becomes your bottleneck, because no matter how often the Flash Player asks for more samples, the amount will always be limited by the frame rate. In this architecture you always end up with the FlashPlayer asking for more samples than you have if the frame rate is too low.
    This is bad news. But can't we chat a little bit and assume that the "sample holes" can be filled by using sample neighbors on the time line? In other words, can't we just  stretch the samples? Well, this is what I came up with:
    private function sampleDataHandler(event:SampleDataEvent):void
         if( audioBuffer.length > 0 )
              var L : Number;
              var R : Number;
              //The sound channel is requesting more samples. If it ever runs out then a sound complete message will occur.               
              const audioBufferSize : uint = _swc.sega_audioBufferSize();
              /*     minSamples, see http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/SampleDataEvent.html
                   Provide between 2048 and 8192 samples to the data property of the SampleDataEvent object.
                   For best performance, provide as many samples as possible. The fewer samples you provide,
                   the more likely it is that clicks and pops will occur during playback. This behavior can
                   differ on various platforms and can occur in various situations - for example, when
                   resizing the browser. You might write code that works on one platform when you provide
                   only 2048 samples, but that same code might not work as well when run on a different platform.
                   If you require the lowest latency possible, consider making the amount of data user-selectable.                         
              const minSamples : uint = 2048;
              /*     For the maximum sample rate of 44100 we still only get 1470 samples:
                   snd.buffer_size = (rate / vdp_rate) = 44100 / 60 = 735.
                   samples = snd.buffer_size * channels = 735 * 2 = 1470.
                   So we need to stretch the samples until we have at least 2048 samples.
                   stretch = Math.ceil(2048 / (735*2)) = 3.
                   snd.buffer_size * channels * stretch = 735 * 2 * 3 = 2790.
                   Bingo: 2790 > 2048 !
              const stretch : uint = Math.ceil(minSamples / audioBufferSize);
              audioBuffer.position = 0;
              if( stretch == 1 )
                   event.data.writeBytes( audioBuffer );
              else
                   for( var i : uint = 0; i < audioBufferSize; ++i )
                        L = audioBuffer.readFloat();
                        R = audioBuffer.readFloat();
                        for( var k : uint = 0; k < stretch; ++k )
                             event.data.writeFloat(L);
                             event.data.writeFloat(R);
              audioBuffer.position = 0;
    After using that method the sound was not choppy anymore! Even though I did hear a few crackling bits here and there the sound quality improved significantly.
    Please consider this implementation as a workaround until Adobe delivers a FlashPlayer that is 3 times faster :-)
    Best wishes,
    - Bernd

Maybe you are looking for