![]() |
|||
|
|
You can read class slides set 11, page 132 and Wolfe book section 11.2.1 to get an idea of privatization.
Specifically, there are three directives which should be used: C$DIR LOOP_PARALLEL, C$DIR LOOP_PRIVATE(), C$DIR SAVE_LAST. C$DIR LOOP_PARALLEL directive forces parallelization of the immediately following loop; C$DIR LOOP_PRIVATE declares a list of variables private to the immediately following DO loop; C$DIR SAVE_LAST causes the thread that executes the last iteration of the loop to write back the private(or local) copy of the variable into the global reference. For more information, you can read on-line document Parallel Programming Guide for HP-UX Systems.
In Polaris, each directives mentioned aboved corresponds to an Asssertion: AssertParallel to C$DIR LOOP_PARALLEL; AssertPrivate to C$DIR PRIVATE and AssertLastValue to C$DIR SAVE_LAST. The Statement class keeps a list of assertions which can be accessed by assertions() method. You can insert assertions into the list of assertions associated with the do statement and Polaris will generate corresponding diretives for you automatically.
PROGRAM TESTThe output file, test.polaris.f:
INTEGER I, J, A(10)
DO I=1, 10
J=I*2
PRINT*, J
A(I)=J
ENDDO
PRINT*, A(2)+A(3), J
END
PROGRAM TESTThe first directive tells the compiler that the following do loop: DO I=1, 10 should be run in parallel. C$DIR LOOP_PRIVATE(J) contains the information that variable J need to be privatized. C$DIR SAVE_LAST makes the variable J at the print statement get the value which is assigned at the last iteration of the do loop.
INTEGER I, J, A(10)
C$DIR LOOP_PARALLEL
C$DIR LOOP_PRIVATE(J)
C$DIR SAVE_LAST
DO I=1, 10
J=I*2
PRINT*, J
A(I)=J
ENDDO
PRINT*, A(2)+A(3), J
END
Suppose variable stmt is the reference of DO I=1, 10 and priv_sym is the symbol variable for J. To insert the directives into the above input code, the implementation could be like this:
AssertParallel * a_parallel=new AssertParallel
stmt.assertions().ins_last(a_parallel)
AssertPrivate * a_private=new AssertPrivate
a_private->arg_list_guarded().ins_last(id(*priv_sym))
stmt.assertions().ins_last(a_private)
AssertLastValue * a_last_value=new AssertLastValue
stmt.assertions().ins_last(a_last_value)
If you have not compiled out mypolaris yet, change to your work directory and make proj5, i.e.
cd ~/minipolaris
make proj5
If you make some changes and want to recompile, just type make at the ddtest directory. Or, if you want to do it from the top-level makefile, you should do (suppose you are at the ddtest directory)
rm libddtest_pkg.so.1If you want to compile all your codes including gotos, bblock, ssa, constant, ddtest, dessa as a whole, also change to your work directory and make projall, i.e.
cd ~/minipolaris
make proj5
cd ~/minipolaris
make projall
Parasol Home | Research | People | General info | Seminars | Resources Parasol Lab, 301 Harvey R. Bright Bldg, 3112 TAMU, College Station, TX 77843-3112 Contact Webmaster Phone 979.458.0722 Fax 979.458.0718
Department of Computer Science and Engineering | Dwight Look College of Engineering | Texas A&M University Privacy statement: Computer Science and Engineering Engineering TAMU |