Re: program freezing

From: Eric Frederich (eric.frederich_at_gmail_dot_com)
Date: Thu Dec 08 2005 - 14:30:57 PST

  • Next message: Tan Guangming: "how to install Berkeley UPC-to-C translator on IBM/POWE4/AIX"
    Dan,
    
         I appreciate you looking into this and I am glad I could help in
    finding a bug.
         I hadn't been working on that program too much before I noticed that
    behavior.
         I almost didn't send this in because my code looked horrible at that
    point since I just wound up taking working sequential code and parallelizing
    it.
         Since then I have replaced those ABS macros with calls to fabs and
    replaced other parts of my code with upc_memget and upc_memput for copying
    shared rows into local memory and then back into shared.
         Now the program actually scales on a single machine with two
    processors.  I just need to get some reduction operations working and it may
    scale on remote machines.
    
    
    Thanks again,
    ~Eric
    
    On 12/8/05, Dan Bonachea <bonachea_at_cs_dot_berkeley_dot_edu> wrote:
    >
    > Hi Eric -
    >
    > It appears that your program has exposed a bug in our UPC translator,
    > which is
    > causing the incorrect behavior. Specifically, your application of the
    > ABS()
    > macro to a shared array element is causing the translator to generate
    > incorrect code.
    >
    > I've submitted the problem to our bug database, and someone should look
    > into
    > it shortly - you can track the status here:
    > http://upc-bugs.lbl.gov/bugzilla/show_bug.cgi?id=1352
    >
    > Apologies for the confusion and inconvenience. In the meantime, the patch
    > to
    > your program shown below provides a workaround.
    >
    > Incidentally, this is probably the way you should write the code anyhow,
    > because it implies fewer communication operations, at least in a naive
    > translation. By reading the (potentially remote) array element into the
    > tmp
    > before operating on it, you guarantee there will be at most one (get)
    > communication operation for that statement. Applying the macro directly to
    > a
    > remote array element (eg ABS(a[j][i])) expands to something like (a[j][i]
    > < 0
    > ? -(a[j][i]) : (a[j][i])), which naively implies two get communication
    > operations unless the optimizer is smart enough to remove one.
    >
    > Hope this helps...
    > Dan
    >
    > --- matrixSolver-orig.upc       2005-12-08 10:12:40.000000000 -0800
    > +++ matrixSolver.upc    2005-12-08 10:13:50.000000000 -0800
    > @@ -71,10 +71,12 @@
    >   //                printf("a[%d][%d] : %f\n",maxrow,i,a[maxrow][i]);
    > fflush(stdout);
    >   //                printf("ABS(a[%d][%d]) : %f\n",j,i,ABS(a[j][i]));
    > fflush(stdout);
    >   //                printf("ABS(a[%d][%d]) :
    > %f\n",maxrow,i,ABS(a[maxrow][i])); fflush(stdout);
    > -                tmpa = ABS(a[j][i]);
    > -                tmpb = ABS(a[maxrow][i]);
    > +                tmpa = a[j][i];
    > +                tmpb = a[maxrow][i];
    > +                tmpa = ABS(tmpa);
    > +                tmpb = ABS(tmpb);
    >   //                printf("tmpa : %f\ntmpb : %f\n",tmpa,tmpb);
    > fflush(stdout);
    > -                if (ABS(a[j][i]) > ABS(a[maxrow][i])){
    > +                if (tmpa > tmpb){
    >   //                    printf("Seting maxrow to %d\n",maxrow);
    >                       maxrow = j;
    >                   }
    >
    >
    > At 02:47 PM 12/7/2005, Eric Frederich wrote:
    > >Hello,
    > >I'd like to share something that has been troubling me.
    > >
    > >Attached I have two files.  One is the program, the other is the input to
    > the
    > >program.
    > >
    > >I compiled the program with
    > >
    > >./upcc -pthreads -o matrixSolver -T=2 matrixSolver.upc
    > >
    > >and run the program like
    > >
    > >./upcrun -n 2 -c 2 -p 2 matrixSolver <http://matrix.500.in>matrix.500.in
    > >
    > >As the program is attached it freezes on me at the following point in the
    > >code.
    > >if (ABS(a[j][i]) > ABS(a[maxrow][i]))
    > >
    > >I take the two operands of this inequality and store them in local
    > variables
    > >tmpa and tmpb.
    > >If you use these variables for the inequality (like if(tmpa > tmpb) ) the
    > >program runs fine and solves the matrix.
    > >
    > >This confuses me greatly since the macro ABS still works since I am using
    > it
    > >when storing the variables in tmpa and tmpb.
    > >
    > >the ABS macro is defined as follows...
    > >
    > >#define ABS(x) (x < 0 ? -(x) : (x))
    > >
    > >Any ideas anyone?
    > >
    > >Also, I hope that I am accomplishing what I wanted to do.  I want to
    > >distribute the rows of the matrix in a round robin fashion.
    > >I haven't got to dynamic memory allocation with UPC yet so I defined the
    > >array as follows.
    > >
    > >shared[1001] double a[1000][1001];
    > >
    > >By doing this is affinity of a[0][0] through a[0][1001] going to the
    > first
    > >thread,
    > >and the affinity of a[1][0] through a[1][1001] going to the next thread,
    > >and the affinity of a[2][0] through a[2][1001] to the next, and so on?
    > >
    > >This is a square matrix with an extra column to store the one dimensional
    > >vector.
    > >
    > >
    > >
    > >Thanks ahead of time,
    > >------------------------
    > >Eric L. Frederich
    > >
    > >#Attachment Converted: "c:\program
    > >files\eudora\data\imap\dominant\inbox\attach\matrixSolver.upc"
    > >
    > >#Attachment Converted: "c:\program
    > >files\eudora\data\imap\dominant\inbox\attach\Makefile.in"
    >
    >
    
    
    --
    ------------------------
    Eric L. Frederich
    

  • Next message: Tan Guangming: "how to install Berkeley UPC-to-C translator on IBM/POWE4/AIX"