Пример #1
0
int main(int argc, char *argv[]) {
     double start, end;
     struct node *p=NULL;
     struct node *temp=NULL;
     struct node *head=NULL;
     
	 printf("Process linked list\n");
     printf("  Each linked list node will be processed by function 'processwork()'\n");
     printf("  Each ll node will compute %d fibonacci numbers beginning with %d\n",N,FS);      
 
     p = init_list(p);
     head = p;

     start = omp_get_wtime();
     {
        while (p != NULL) {
		   processwork(p);
		   p = p->next;
        }
     }

     end = omp_get_wtime();
     p = head;
	 while (p != NULL) {
        printf("%d : %d\n",p->data, p->fibdata);
        temp = p->next;
        free (p);
        p = temp;
     }  
	 free (p);

     printf("Compute Time: %f seconds\n", end - start);

     return 0;
}
Пример #2
0
int main(int argc, char *argv[]) {
    double start, end;
    struct node *p=NULL;
    struct node *temp=NULL;
    struct node *head=NULL;

    printf("Process linked list\n");
    printf("  Each linked list node will be processed by function 'processwork()'\n");
    printf("  Each ll node will compute %d fibonacci numbers beginning with %d\n",N,FS);      

    p = init_list(p);
    head = p;

    int count = 0;
    for(struct node *i = head; i != NULL; i = i->next)
        count++;
    struct node *parr[count];
    for(int i=0; i<count; i++){
        parr[i] = p;
        p = p->next;
    }

    start = omp_get_wtime();
    #pragma omp parallel for schedule(static, 1)
    for(int i=0; i<count; i++ ){ 
            processwork(parr[i]);
    }

    end = omp_get_wtime();
    p = head;
    while( p != NULL ) {
        printf("%d : %d\n",p->data, p->fibdata);
        temp = p->next;
        free (p);
        p = temp;
    }
    free (p);

    printf("Compute Time: %f seconds\n", end - start);

    return 0;
}
Пример #3
0
int main(int argc, char *argv[]) {
     double start, end;
     struct node *p=NULL;
     struct node *temp=NULL;
     struct node *head=NULL;
     struct node *parr[NMAX]; 
     int i, count=0;
     
     printf("Process linked list\n");
     printf("  Each linked list node will be processed by function 'processwork()'\n");
     printf("  Each ll node will compute %d fibonacci numbers beginning with %d\n",N,FS);      
 
     p = init_list(p);
     head = p;


     start = omp_get_wtime();
     {
        while (p != NULL) {
		   processwork(p);
		   p = p->next;
        }
     }

     end = omp_get_wtime();

     printf("serial Compute Time: %f seconds\n", end - start);


     p = head;

     start = omp_get_wtime();
     {
        // count number of items in the list.  Strictly speaking this isn't 
        // needed since we know there are N elements in the list.  But in 
        // most cases you don't know this and need to count nodes. 
        while (p != NULL) {
	  	   p = p->next;
               count++;
        }
      
        // traverse the list and collect pointers into an array.
        p = head;
        for(i=0; i<count; i++) {
               parr[i] = p;
               p = p->next;
        }
       
        // do the work in parallel 
        #pragma omp parallel 
        {
           #pragma omp single
               printf(" %d threads \n",omp_get_num_threads());
           #pragma omp for schedule(static,1)
           for(i=0; i<count; i++)
		   processwork(parr[i]);
        }
     }

     end = omp_get_wtime();
     p = head;
	 while (p != NULL) {
        printf("%d : %d\n",p->data, p->fibdata);
        temp = p->next;
        free (p);
        p = temp;
     }  
     free (p);

     printf("Compute Time: %f seconds\n", end - start);

     return 0;
}