reset password
Author Message
ahnman341
Posts: 22
Posted 19:47 Mar 17, 2015 |

Do we need to compile a .o object from mbarrier.h to use barriers in .cpp files?  Or does #include "mbarrier.h" within testmb.cpp suffice?

 

So far, I've tried 

>g++ -o testmb testmb.cpp util.o

and I get a long error message.  What do I type into the command line to run testmb.cpp?  

 

Last edited by ahnman341 at 20:42 Mar 17, 2015.
se1k1h1mawar1
Posts: 121
Posted 20:02 Mar 17, 2015 |

I don't think you need to compile a .o object from mbarrier.h to use barriers in .cpp files.
Including below statements within testmb.cpp  worked for me.


1)   #include "utility.h"
2)   #include "mbarrier.h"
3)   extern "C" {
    int process_fork(int nproc);
    void process_join(int nproc, int id);
    int *shareint(int size, int& id);
    int *sharerealarray(int size, int& id);
    int *sharelist (int size, int& id);
    int *sharereal(int size, int& id);
    void spin_lock_init(int& lock, int condition);
    void spin_lock(int lock);
    void spin_unlock(int lock);
    void clean_up_shared(int id);
    void clean_up_sem(int id);
} // I'm sure some of these are not necessary. Probably we only need sharelist

 

To compile it, I just typed in "g++ testmb.cpp util.o" to run it.
I also changed  b[0]->Barrierinit(6);   to   b[0].Barrierinit(6); in testmb.cpp.

Thanks,

 

Last edited by se1k1h1mawar1 at 20:11 Mar 17, 2015.
ahnman341
Posts: 22
Posted 20:37 Mar 17, 2015 |

So to clarify, we need to modify the original file testmb.cpp on Dr. Pamula's site??

 

I have modified testmb.cpp to include:

#include "utility.h"

extern "C"{

..

..

}

but I'm still getting the same compilation error

 

Also, in testmb.cpp, the original code for Barrierinit() is:

b->Barrierinit(6);   //Initialize the barrier to
                    //   block 6 processes.

 

You changed this to 

b[0]->Barrierinit(6);  ???

 

 

ahnman341
Posts: 22
Posted 20:47 Mar 17, 2015 |

I think it would be helpful if you gave me a step-by-step on how you got testmb.cpp to run on mars.

 

What I have done:

1.  Download and upload via FTP to mars account the following:

testmb.cpp

mbarrier.h

2.  try to compile testmb.cpp by:

>g++ -o testmb testmb.cpp util.o

 

Thanks

se1k1h1mawar1
Posts: 121
Posted 20:53 Mar 17, 2015 |

I also included "#include "mbarrier.h".

Below is the testmb.cpp I have, and below that is the output I get.:

----------------

#include <math.h>^M
#include <iostream>^M
using namespace std;^M
^M
#include "mbarrier.h"^M
#include "utility.h"^M
extern "C" {
    int process_fork(int nproc);
    void process_join(int nproc, int id);
    int *shareint(int size, int& id);
    int *sharerealarray(int size, int& id);
    int *sharelist (int size, int& id);
    int *sharereal(int size, int& id);
    void spin_lock_init(int& lock, int condition);
    void spin_lock(int lock);
    void spin_unlock(int lock);
    void clean_up_shared(int id);
    void clean_up_sem(int id);
}
const int nproc = 5;^M
Barrier* b;  // declare a barrier.^M
^M
int main()^M
{^M
        int i;^M
   int id;^M
   int shareid;^M
^M
   b = (Barrier*)sharelist(sizeof(Barrier)*3, shareid);^M
^M
          // Note that the size of barrier is 16 bytes.^M
          //     Four integers defined in the barrier.^M
^M
   b[0].Barrierinit(6);   //Initialize the barrier to^M
                    //   block 6 processes.^M
^M
^M
   id=process_fork(6);^M
^M
^M
         //STEP I of the computation using 6 processes^M
^M
    cout<<id<<"  arriving at first barrier"<< endl; ^M
    // Note the arrival of processes at first barrier ?^M
^M
    b[0].WaitAtBarrier();  // Block the processes till^M
                        //   all of them reach this point^M
^M
    cout<<id<<" releasing the first barrier" <<endl;  ^M
   // Note the processes released from the first barrier^M

 ^M
^M
    cout<<id<<"  arriving at next barrier"<< endl; ^M
    // Note the arrival of processes ^M
^M
    b[0].WaitAtBarrier(); //Reuse the barrier to block all the processes^M
^M
    cout<<id<<" releasing the second time"<<endl;   ^M
                                // Note the order of processes^M
                       //  as they are released again for the second time^M
^M
^M
   clean_up_shared(shareid);^M
^M
           b[0].SemRelease();             // Release Semaphore used in^M
                                        //   the barrier^M
    return 0;^M
^M
^M
}^M

 

-------------------------------------

1  arriving at first barrier
2  arriving at first barrier
3  arriving at first barrier
4  arriving at first barrier
0  arriving at first barrier
5  arriving at first barrier
5 releasing the first barrier
5  arriving at next barrier
0 releasing the first barrier
3 releasing the first barrier
2 releasing the first barrier
3  arriving at next barrier
4 releasing the first barrier
2  arriving at next barrier
4  arriving at next barrier
0  arriving at next barrier
1 releasing the first barrier
1  arriving at next barrier
4 releasing the second time
3 releasing the second time
1 releasing the second time
2 releasing the second time
5 releasing the second time
0 releasing the second time

 

 

 

Please let me know if I'm misunderstainding something.

Thanks,

Last edited by se1k1h1mawar1 at 20:54 Mar 17, 2015.
ahnman341
Posts: 22
Posted 21:13 Mar 17, 2015 |

OMG i got it to work.

 

 

<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3

<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3

<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3
<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3
<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3
se1k1h1mawar1
Posts: 121
Posted 21:22 Mar 17, 2015 |
ahnman341 wrote:

OMG i got it to work.

 

 

<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3

<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3

<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3
<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3
<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3

Congratulations!