[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] parallellisering



> Hmmmm.
> ---------
> int sum = 0;
> int i;
> for (i = 0; i < 10000; i++) {
>   sum++;
> }
> ---------
> kan ikke (med fordel) paraleliseres til 
> 
> ---------
> int sum = 0;
> int i; 
> semaphor_hvad_ved_jeg sem = INIT_SEM;
> 
> process 1 og 2:
> for (i = 0; i < 5000; i++) {
>   lock(sem);
>   sum++;
>   release(sem);
> }
> ----------
> 
> Så, det har en paralleliseringsgrad på 0....

Klart, men klodset, hvorfor ikke:

int sum,sum2,sum3;

sum=sum2=sum3=0;

//loop 1:
for (i=0;i<N;i+=2)
	sum2++;
//loop 2:
for (i=1;i<N;i+=2)
	sum3++;

sum=sum2+sum3;


(spilder 2x4 bytes, men skulle være 2x hurtigere.)
startværdien for i passes bare over som argument ved
pthread_create, og den skal steppe antallet af tråde
(her 2 tråde). Men som sagt, det kører kun ca 23% hurtigere??

__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *