Would someone tell me something about multithread and multiprocessor

Hey, would you be so kind to tell me something about how to progrmme with using multithread in multiprocessro? and where can I find something about it? My problem is that
Assume that you have to write a computer program that will receive as input a single array
storing a large number of integers. The program has to compute the prefix sums of the
number sequence.
Given a sequence of numbers x1, x2, ..., xn, the prefix sums are the partial sums:
s1 = x1
s2 = x1 + x2
sn = x1 + x2 + ... + xn
�You have to be prepared to write a program for program should be able to use a variable, user-specified, number of processors. For
example, the user should be able to run the program using any number of processors P
between 1 and 16. The number of processors P can either be selected using a command
line argument or the program can prompt the user.
�Your program should be able to sum a variable, user-specified, number of integers. The
integers in the input sequence should be randomly generated inside your program. (That
is, the user will input n, and the program will then randomly generate n numbers.)
�Your program should print out (either to the standard output or to a file) in ascending
order the prefix sums computed: s1, s2, �, sn.
Can someone give me some help? I have no idea about how to do it?
thanks a lot of

I think perhaps you are asking about how to create threads in Java? I'm not sure, but I'll give you some background anyway. Basically all that you need to know is documented in the class java.lang.Thread. If you want a class to run on a separate thread then you can do one of two things:
(a) define a class that extends Thread.
(b) define a class that implements Runnable.
I prefer the latter, but it's up to you. So, for example, if I have some computationally expensive algorithm to execute I would define a class like this:
public class ImExpensive implements Runnable {
����public void run() {
��������<insert code here>
����}
Then when you want to run the algorithm you do this:
����ImExpensive o = new ImExpensive();
����new Thread(o).start();
The second line in this case constructs a thread that the object 'o' can run on (the start() method causes the run() method in the ImExpensive class to execute).
Now, as for running on multi-processors, I have never done this so I am not too sure. But all that you have to do is figure out a way of associating the thread that was created with a particular processor.
Also, be careful when using threads. Everything will be OK if your computations are mutually exclusive (ie: they aren't interdependent). If they aren't then you might run into what is sometimes called "the racehorse problem". This is a phenomenon that occurs because you can't guarantee which threads are going to finish first or indeed the order of interleaved operations. It's difficult to describe but this tutorial may help you out.
http://java.sun.com/docs/books/tutorial/essential/threads/
Hope that helps. :)
Ben

Similar Messages

  • May someone tell me  something about the thread

    The ODP.NET document seems to have little words about the thread,or maybe it is the database who deals with the thread. i have some question aboue it.
    I define a variable in a package specification,
    CREATE OR REPLACE PACKAGE TSTpkg
    is
    counter NUMBER DEFAULT 0;
    END TSTpkg;
    then deal with it in a function
    FUNCTION addc RETURN NUMBER
    AS
    cnt NUMBER:=0;
    BEGIN
    LOOP
    EXIT WHEN admin.tstpkg.counter>100;
    tstpkg.counter:=admin.tstpkg.counter+1;
    cnt:=cnt+1;
    END LOOP;
    RETURN cnt;
    the cnt indicate the number the loop runs,in a single thread program,it will always return 100,for counter is default by 0.Then in C#, i wrote a methord to invoke the funciton"addc" and return the value the function"addc" returns.As far as I am concerned,the variable defined in the package specification should be seen as static element,so if two thread access it, there is just one counter,and the sum of the values return by the two methords invoked in two threads should be 100. But the result is each of the thread returns 100.
    How does the database treat the variable defined in the package specification on the earh?And shouldn't I see it as static one ?
    Who can tell me truth?3ks very much
    (PS: I am Chinese, please forgive me poor engilsh)

    Hi,
    Each database session gets it's own copy of plsql package variables, they're not shared between sessions.
    Cheers
    Greg

  • Hi, i have a macbook air and i've been having problems with the camera when i'm using skype. i know im no the 1st one and i'd like to know when apple or someone 'll do something about this.

    hi, i have a macbook air and i've been having problems with the camera when i'm using skype. i know im no the 1st one and i'd like to know when apple or someone 'll do something about this.

    Try reinstalling Combo Update.
    http://support.apple.com/kb/DL1676
    Best.

  • Tell me something about bending of iPhone 6Plus

    Tell me something about bending of iPhone 6Plus ?

    What's to tell?  If you put enough pressure/force on any smartphone, it will bend or break.  There isn't a smartphone in the world that won't suffer damage if enough pressure/force is used, and the iPhone 6 Plus is sturdier than the average, based upon Consumer Reports tests.
    Put it in a protective case to help minimize the risk.

  • Pls tell me something about Bank configuration

    Hi,
    Please tell me something about Bank configuration
    Thanks

    Hi,
    Please refer the following for Bank Configuration steps:
    Bank configuration:
    To set up Electronic Bank Statements (EBS)
    1. Create House Bank and Account ID (FI12)
    2. Setup EDI Partner Profile for FINSTA Message Type (WE20)
    3. Configure Global Settings for EBS (IMG)
    - Create Account Symbols
    - Assign Accounts to Account Symbols
    - Create Keys for Posting Rules
    - Define Posting Rules
    - Create Transaction Types
    - Assign External Transaction Types to Posting Rules
    - Assign Bank Accounts to Transaction Types
    4. Define Search String for EBS(Optional)
    - Search String Definition
    - Search String Use
    5. Define Program and Variant Selection
    Additional information is also available in the SAP Library under:
    Financial Accounting > Bank Accounting (FI-BL) > Electronic Bank Statement >
    Electronic Account Statement Customizing.
    Bank Reconcilliation Statement
    The following are the steps for BRS:
    Create Bank Master Data - This can be created through T.Code FI01 or you can also create the house bank through IMG/FA/Bank accounting/Bank account
    2. Define House Bank
    3. Set up Bank selection payment programe- IMG/FA/ARAP/BT/AUTOIP/PM/Bank selection for payment prg.
    a. setup all co codes for payment transaction - Customer and vendors
    b.setup paying co codes for payment transactions
    c.setup payment method per country
    d.setup payment method per co code for payment transaction
    e.setup bank determination for payment transaction
    Please go for Cheque mangement using T code FCHI (IMG/FA/ARAP/BT/OP/AutoOp/PaymentMedia/CheckManagement) and for void reasons FCHV. You can create Bank Reconcilliation statement by TC FF67 (SAP/AC/Treasury/CashManagement/Incomings/ManualBankStatement) . Don't forget to keep the opening Balance as zero. Use FBEA for post process.
    All the steps together will lead to (FF67) Bank reconciliation statement.
    Thanks,
    Prithwiraj.

  • I have an apple tv 1st generation, and there is a setting for airtunes. can someone tell me what this is and how to use it?

    I have an apple tv 1st generation, and there is a setting for airtunes. can someone tell me what this is and how to use it?

    I've looked at that, but on my PC, "look for remote speakers connected with airtunes" isn't an option.
    The only options I get are "prevent ipods [etc] from syncing automatically" , "warn me when [X %] of the data on this computer will be changed" and "forget all remotes". Its also got a list of backups I have saved, as well as a button to reset sync history.
    When I am playing a song, the "airplay" button isn't even visible.
    I am sure that the apple tv setting is on as well. Is there anything else you can help me with?

  • I love AI love Apple.  I own an iMac, a MacbookPro, an iPad, and an iPhone.  I've been a loyal Mac user since the '80's.   But, please, when are you going to do something about iCal and its Reminders component?  Attaching documents is clumsy. If you're on

    I love AI love Apple. I own an iMac, a MacbookPro, an iPad, and an iPhone.  I’ve been a loyal Mac user since the ‘80’s.   But, please, when are you going to do something about iCal and its Reminders component?  Attaching documents is clumsy. If you’re on iCloud, as I am, repeating events is impossible.  The ability to copy text or graphics into either events or Reminders doesn’t really exist.  This is an easy fix.   Why not get it done? 

    Maybe things will improve this summer,
    http://www.apple.com/macosx/mountain-lion/features.html
    Regards,
    Captfred

  • Please help! I am currently using iPhone 5 and changing to iphone 6 in sometime. I have taken backup of my photos, videos, contacts, notes and whatsapp. The only thing that remains is my iMessage. Can someone tell me how to backup and restore my iMes

    I am currently using iPhone 5 and changing to iphone 6 in sometime. I have taken backup of my photos, videos, contacts, notes and whatsapp. The only thing that remains is my iMessage. Can someone tell me how to backup and restore my iMessages?

    iMessages are backed up in the normal backup of your phone so it will be restored when you restore the backup.

  • HT4009 I make an In-App purchase and my device fails to complete the purchase. Could you do something about it and prevent it from ever happening again?

    To iTunes Store
    I've being trying to make an In-App purchase and it doesn't work. I get this message that says the pruchase can't be completed. Could you do something about it and prevent it from ever happening again?
    Sincerely
    Cameron

    We are itunes users just like you.
    You should contact itunes support

  • The call library function require us to define the type of parameter that w are using.The type of parameter in cludes numeric, array, string,wav​eform and adapt to type.I would like to know more about waveform and adapt to type.

    In the labview manual, there is very little mention about the use of waveform.How is this waveform being called and can i have an example to see how this work.
    Also in the adapt to type paramete, what does this parameter do and in what circumstances do we need to use it.The manual say something about the use of this parametr.It says that scalar elements in arrays or clusters are in line.For example a cluster containing anumeric is passed as pointer to a structure containing a numeric. What does this statement mean?
    Can i imply t
    hat if my input is a struct, can i use a adapt to type parameter to overcome this incompatibility?Can i also have an example to let me have a better idea.thank you

    I'm going to share my experience with the "Adapt to Type" parameter.
    Attached to this message is an example. The attachment is a zip file with three files: a dll, a c file and a vi written in LabVIEW 6. The dll contains a function that return a structure with 3 values (like the coordinates of a point in space, that is, (x, y, z)). You can see how the function was constructed by looking at the c file.
    In LabVIEW, I created a cluster with the same three parameters. Then, I configured the call library function following the function prototype as in the c file. For the point variable I use "Adapt to Type".
    I hope this can give you a head star.
    Best regards;
    E. Vargas
    www.vartortech.com
    Attachments:
    pointexample.zip ‏63 KB

  • How do I get rid of a strange symbol where I ask for a website that won't let me access Firefox & tells me something about "ownership"?

    The symbol is not a padlock. It kind of looks like some sort of bird. I believe it mentioned something about encryption.

    Can you attach a screenshot?
    *http://en.wikipedia.org/wiki/Screenshot
    *https://support.mozilla.org/kb/how-do-i-create-screenshot-my-problem
    Use a compressed image type like PNG or JPG to save the screenshot.
    If you have a normal http connection or a secure connection with mixed content the the Site Identity Button is a basic globe.
    *https://support.mozilla.org/kb/Site+Identity+Button
    *http://blog.mozilla.org/ux/2012/06/site-identity-ui-updates/

  • Would someone tell me the difference between PS13 and Elements !

    what are the differences between elements 13 and PS 13

    I'm sure there's a link somewhere which lays out the differences explicitly.  But from a top level, Elements is a slimmed down version of Photoshop that is geared towards a quicker and easier user experience.  It has more "one click" options for optimizing color, reducing redeye, etc - the main, basic edits that most people want to do to their photos.   Photoshop, on the other hand, is an advanced photo editor and comes with a learning curve; it's designed to be a full fledged digital editor from the "film" photographer, to the digital artist, compositors, layout, etc.  Even basic edits can be difficult to figure out until you know your way around the program.  It' more powerful, but more difficult to learn.  That said, some people don't want to spend the time learning it, they just want some basic, quick editing tools.
    I can't remember the list off the top of my head, but Elements had a couple restrictions that made it a non-starter for me.  First and foremost, Elements won't let you edit multiple layers in 16 bits.  Something that won't affect many, but for any high level compositing it's a not go.  On top of that, they removed features like the pen tool, paths, curves, channels, smart objects, etc.  These probably don't mean anything to you, but to those of use that use PS these are the basic building blocks of our work.

  • Would someone tell me the fuzzy concept

    I try to use java to read a file about 16Mb to a string, first it's out of memory, and then I increase the heap use -mx200000000, make it to about 200Mb. It can handle the file, but it still take about 20-30 seconds to read it. and I use another tool like textpad to open it, after i click the filename,it open thoroughly soon. To me it's hard to understand why it takes a short time to read it. and my program can not?
    but I wonder the factors that affect the speed of reading a file is my program or java's limitation. If you have any idea or hypothesis, would you please tell me, make me know more about it?
    my program like this:
    fis = new FileInputStream (fileName);
    int size = fis.available ();
    byte[] bytes = new byte [size];
    fis.read (bytes);
    str = new String (bytes);

    You need to use a BufferedInputStream and then read from the buffer. You are doing little operations many times over which takes time. You need to do big operations and do them less frequently to improve the speed of your program.

  • Could someone tell me alittle about the AbstractDocument please

    Hi, hope someone can help,
    I am making a small internet chat program, and had it working great using JTextArea, but I wanted to style the text, and so switched to JTextPane, and using the AbstractDocument.
    Here these two code chunks are setting up my editable input text area, for typing, and a view area, for viewing.
            StyledDocument styledDoc = viewArea.getStyledDocument();
            if (styledDoc instanceof AbstractDocument) {
                doc = (AbstractDocument)styledDoc;
                //doc.setDocumentFilter(new DocumentSizeFilter(MAX_CHARACTERS));
                doc.setDocumentFilter(new DocumentFilter());
            } else {
                System.err.println("Text pane's document isn't an AbstractDocument!");
                System.exit(-1);
            StyledDocument styledDoc2 = typeArea.getStyledDocument();
            if (styledDoc2 instanceof AbstractDocument) {
                doc2 = (AbstractDocument)styledDoc2;
                //doc.setDocumentFilter(new DocumentSizeFilter(MAX_CHARACTERS));
                doc2.setDocumentFilter(new DocumentFilter());
            } else {
                System.err.println("Text pane's document isn't an AbstractDocument!");
                System.exit(-1);
            }I have only got Bold working in the input box at the minute, I have it implemented as a JButton, when pressed does this:
         if(!hasViewAreaFocus)                    
              new StyledEditorKit.BoldAction().actionPerformed(null);     Where that boolean lets me know if the selected text is in the viewArea, so I don't style already 'sent' text.
    I am currently sending text to this other area as so
         try{doc.insertString(doc.getLength(), typeArea.getText() ,new SimpleAttributeSet());}
         catch (BadLocationException ble) {System.out.println("ble");}Forgetting the network thing for the minute, as you can see, I'm using SimpleAttributeSet() to get the text into the viewArea, so the style disappears when it arrives in the new document in the JTextPane.
    The question is basically, how do I get the styles to go with the text to the viewArea ? I don't understand how when I toggle 'Bold' on, where java is remembering that the text that I selected should be bold ? Is it storing all the text in some area of memory in a markup style way ? If so, can I pass this markup text to the other document so it knows what to style?
    The problem is I don't understand how java is remember what to style in the first place, and therefore how to pass it on. Maybe it's stored in AttributeSet?
    Thanks in advance for any light you can shed on this for me,
    Cheers

    ok,
    At this little tutorial here:
    http://www.developer.com/tech/article.php/610011
    It says
    "The Document interface is the content model for Swing text components. Every Swing text component has an instance of Document associated with it. The Document contains both the content for its component as well as any style information for the rendering of the content. All content is stored in the Document's Element array. Style information is stored in each Element as an AttributeSet. We'll get into AttributeSets in the next article, when we discuss styled text components. "
    Mainly concentrating on :
    All content is stored in the Document's Element array. Style information is stored in each Element as an AttributeSet.
    This would indicate that each time a new attribute is applied to something that it is stored as a separate String in an array, along with the attribute relating to it, would it ?
    I've looked here:
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JTextPane.html#getParagraphAttributes()
    And here :
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/text/Document.html
    But still cannot figure out a way to do this, I presume I must get at the Document 'array', and if I had this everything would be fine.
    Should I run through every single charactor in the 'editable' JTextPane, check its attribute and add it my my own special made class?, and pass this class to 'non-editable / viewable-only' JTextPane ?
    Any opinions would be very helpful.

  • Not understanding something about margins and header

    Pages 2 5.5.3
    Mac OS 10.10.2
    I'm trying to rap my head around how pages does headers.
    I think of a header as a place were stuff goes so that it occurs at the top of each page. I would expect it to be positioned at the bottom of the top margin. For instance, with a top margin of .5 in and a header of 1. in, I would expect my header stuff to start at .5 in and my non header stuff to start at 1.5 in.
    This is what I observed. Her are a couple of clarifications to start:
    –All measures are vertical measures
    –Origin represents the offset were an object placed at zero in the body of the document appears.
    Top Margin, set to .5 in. Origin at .5 in as expected.
    -Add a 1 in header. origin moves to 1 in. I  would expect the origin to move to 1.5 in, .5 in top margin + 1 in for the header.
    -Add some 24 pt text to the header and the origin moves down even further, by at least a 1/3 in (24/72). Since 1/3 in is clearly less than one in, i would not expect the origin to change at all since the text would easily fit within 1 in.
    This is what i am seeing. Without a header, the origin is the height of the top margin. The header appears to ignore the top margin and makes its start at the header height and grows downward from there. This seems wrong.
    Can someone steer me straight?

    Here's my settings.
    Here's my results.
    See, the header starts at 1. inch. I do not have the dimensions reversed.

Maybe you are looking for

  • Deployment Error in NWDS 7.2

    Hi All, My server and NWDS are on same patch level. Once i am trying to deploy a simple scenario, i am getting below deployment error. Status ERROR Plugin : com.sap.ide.tools.services code=0 Deployment problems children=[ Status ERROR Plugin : com.sa

  • Join Line Segments (road segments) SDO_AGGR_UNION/SDO_AGGR_CONCAT_LINES

    Hi, I have road segments I need to join/merge in order to get the complete road axe. Unfortunately I have some segements which are not joined and the resulting road axe has a gap. When I look at the road segements and the join result it seems to me t

  • Save a big memory object to fi

    Hi, in my App, I have a image which may be as big as 8M bytes. I would like to save it to a file to iphone local disk. I know I can make it to NSObject (or NSData?). My questions is how can I set the path of this file. thanks, ff

  • HT2311 WHAT IF MY MAC IS NOT THE LEAST SYSTEM?

    I download the latest Itunes but It said my computer is not the right system... so what if I dont want to update and pay 19$? I didnt update my another macbook pro but I can still use the new itunes!! for this one, I can not get on to itunes store, o

  • Why should avoid OLTP compression on tables with massive update/insert?

    Dear expert, We are planning oracle OLTP compression on a IS-U system, could you tell me Why should avoid OLTP compression on tables with massive update/insert? What kind of impact on the performance in the worst case? Best regards, Kate