OpenMP code (example a1):
• #pragma omp parallel for
for(
i=1; i < n; ++i )
b[i] = (a[i] + a[i-1]) / 2.0;
Explicit Windows threads code:
• DWORD ThreadFn( VOID* pData ) { // primary function
for( int i = pData->Start; i <
pData->Stop; ++i )
b[i] = (a[i] + a[i-1]) / 2.0;
return 0;
}
• for( int i=0; i < n; ++i ) // create thread team
hTeam[i] =
CreateThread( 0, 0, ThreadFn, pDataN, 0, 0 );
• WaitForMultipleObjects( n, hTeam, TRUE, INFINITE
);
// wait until
done
• for( int i=0; i < n; ++i ) // clean up
CloseHandle( hTeam[i]
);