git-svn-id: svn://anubis/gvsu@188 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
379d7759f8
commit
ee58c58087
@ -21,12 +21,37 @@
|
|||||||
\noindent
|
\noindent
|
||||||
\begin{enumerate}
|
\begin{enumerate}
|
||||||
\item[1.]{
|
\item[1.]{
|
||||||
in progress
|
Break the ``parallel region'' into a function accepting a \texttt{void *}
|
||||||
|
parameter.
|
||||||
|
Before the ``parallel region'' create a \texttt{for} loop which loops
|
||||||
|
\textit{n} times (where \textit{n} is the number of threads),
|
||||||
|
invoking \texttt{pthread\_create()} once for each thread.
|
||||||
|
Any variables local to the function containing the ``parallel region''
|
||||||
|
that the ``parallel region'' function needs access to
|
||||||
|
would have to be stored as pointers in a structure whose address was
|
||||||
|
passed as an argument to the thread function.
|
||||||
|
Then, the thread would run the code in the ``parallel region''.
|
||||||
|
After the region, a \texttt{for} loop would exist to loop over all
|
||||||
|
the threads created in the first loop and execute \texttt{pthread\_join()}
|
||||||
|
for each one.
|
||||||
}
|
}
|
||||||
|
|
||||||
\vskip 2em
|
\vskip 2em
|
||||||
\item[2.]{
|
\item[2.]{
|
||||||
in progress
|
Each thread could store its result into an array indexed by its ID.
|
||||||
|
Then, when computation is complete, a regular \texttt{for} loop
|
||||||
|
within an OpenMP parallel region could iterate
|
||||||
|
$\lceil \log_2 n \rceil$ times.
|
||||||
|
In the first iteration, threads where $ID\mod 2 = 0$ would perform
|
||||||
|
the reduction operation on their array value and the array value
|
||||||
|
at index $ID + 1$ while the rest of the threads are idle.
|
||||||
|
In the second iteration, threads where $ID\mod 4 = 0$ would perform
|
||||||
|
the reduction operation on their array value and the array value
|
||||||
|
at index $ID + 2$ while the rest of the threads are idle.
|
||||||
|
This process would repeat (doubling the mod value and offset index
|
||||||
|
each time) until the reduction operation has been
|
||||||
|
performed to produce the final result value at index 0 of the
|
||||||
|
array.
|
||||||
}
|
}
|
||||||
|
|
||||||
\end{enumerate}
|
\end{enumerate}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user