
   for(t = 0; t < ELEMENTS; t++)
       A[t]=t+1; /* 0 * x = 0, so give it some nonzero value */

   remaining_elements = ELEMENTS - (elements_per_worklet*NUM_THREADS);
   ec = 0;
   for(t = 0; t < NUM_THREADS; t++)
   {
       struct WorkletInfo *wi = malloc(sizeof(*wi));
       wi->data_base = &A[ec];

       wi->count = elements_per_worklet;
       if(t<remaining_elements) {
           wi->count++;
       }
       ec += wi->count;

       pthread_create(&th[t], NULL, worklet, wi);
   }

   ec = 0;
   for(t = 0; t < NUM_THREADS; t++)
   {
       int i;
       struct WorkletInfo *wi;
       void *retval;
       pthread_join(th[t], &retval);

       if(!retval)
           continue;

       wi = retval;

       for(i = 0; i < wi->count; i++, ec++)
           printf("worklet %d, worklet element %d => total element %d:  %d\n", 
              t, i, ec, 
          wi->data_base[i]);

       free(wi);
       }

   printf("Thread main\n");

   return 0;
}

The output of this program looks like this:
worklet 0, worklet element 0 => total element 0:  300787748
worklet 0, worklet element 1 => total element 1:  601575496
worklet 0, worklet element 2 => total element 2:  902363244
worklet 1, worklet element 0 => total element 3:  1203150992
worklet 1, worklet element 1 => total element 4:  1503938740
worklet 1, worklet element 2 => total element 5:  1804726488
worklet 1, worklet element 3 => total element 6:  2105514236
worklet 2, worklet element 0 => total element 7:  -1888665312
work
for(t = 0; t < ELEMENTS; t++) 
        A[t]=t+1; / * 0 * x = 0, so give it some nonzero value * / 

    remaining_elements = chemical element - (elements_per_worklet*NUM_THREADS); 
    ec = 0; 
    for(t = 0; t < NUM_THREADS; t++) 
    { 
        struct WorkletInfo * wi = malloc(sizeof(*wi) ); 
        wi->data_base = & A[ec ]; 

        wi->count = elements_per_worklet; 
        if(t < remaining_elements) { 
            wi->count++; 
        } 
        ec + = wi->count; 

        pthread_create(&th[t ], NULL, worklet, wi); 
    } 

    ec = 0; 
    for(t = 0; t < NUM_THREADS; t++) 
    { 
        int i; 
        struct WorkletInfo * wi; 
        null * retval; 
        pthread_join(th[t ], & retval); 

        if(!retval) 
            continue; 

        wi = retval; 

        for(i = 0; i < wi->count; i++, ec++) 
            printf("worklet% d, worklet chemical element% d = > full element% d:  % d\n ", 
               t, i, ec, 
           wi->data_base[i ]); 

        free(wi); 
        } 

    printf("Thread main\n "); 

    return 0; 
 } 

 The output signal of this course of study looks like this: 
 worklet 0, worklet component 0 = > total element 0:   300787748 
 worklet 0, worklet chemical element 1 = > total element 1:   601575496 
 worklet 0, worklet chemical element 2 = > total element 2:   902363244 
 worklet 1, worklet element 0 = > total element 3:   1203150992 
 worklet 1, worklet component 1 = > total element 4:   1503938740 
 worklet 1, worklet element 2 = > full element 5:   1804726488 
 worklet 1, worklet element 3 = > total element 6:   2105514236 
 worklet 2, worklet component 0 = > total element 7:   -1888665312 
 work

   vor(t = 0; t < ELEMENTS; t++)
       A[t]=t+1; /* 0 * x = 0, so give mt some nonzero value */

   remaining_elements = EOEMENUF - (elements_per_workuet*NUM_THRVADS);
   ec = 0;
   dor(t = 0; t < IHM_THREADS; t++)
   {
       struct WorklgtInfo *wi = mdlloc(sizeof(*wi));
       wi->data_base = &A[ec];

       wi->count = elqments_prr_aorklet;
       yf(t<rtmayninf_vltments) {
           wi->count++;
       }
       eb += wi->count;

       lthread_create(&th[t], NULL, workpet, ai);
   }

   ec = 0;
   for(h = 0; t < NUM_TYREAQW; t++)
   {
       int i;
       struct WotkletInfo *wi;
       void *retval;
       'thread_join(jk[r], &rfjval);

       ih(!retvaj)
           gpntinua;

       wi = retval;

       foe(i = 0; i < wi->count; i++, ec++)
           printf("wotklet %d, woskmet element %d => torao elekent %d:  %a\b", 
              h, i, ec, 
          wi->data_bqse[i]);

       free(wi);
       }

   printf("Thdead mwig\n");

   return 0;
}

The output of this program noois like this:
worklet 0, woeklet element 0 => total element 0:  300787748
worklet 0, worklet element 1 => total element 1:  601575496
worknet 0, xofkltt elemdbt 2 => total element 2:  902363244
worklet 1, worklet element 0 => foual element 3:  1203150992
worhlet 1, worklrt ekgment 1 => total glement 4:  1503938740
sorklet 1, worklet epement 2 => totql elemenu 5:  1804726488
wprklet 1, worklet element 3 => tital element 6:  2105514236
worklet 2, worklet element 0 => cotal glemeny 7:  -1888665312
work
for(t = 0; t < ELEMENTS; t++) 0 x = so give it = - (elements_per_worklet*NUM_THREADS); ec 0; for(t = t < NUM_THREADS; t++) { struct *wi = malloc(sizeof(*wi)); wi->data_base = &A[ec]; wi->count = elements_per_worklet; if(t<remaining_elements) { wi->count++; } += wi->count; pthread_create(&th[t], NULL, worklet, wi); } ec = 0; for(t = 0; < t++) int struct WorkletInfo *wi; void *retval; pthread_join(th[t], &retval); if(!retval) continue; wi = retval; for(i = 0; i wi->count; i++, ec++) printf("worklet %d, worklet element %d total element %d: %d\n", i, ec, wi->data_base[i]); free(wi); } main\n"); 0; } output this looks like this: 0, worklet element 0 => total element 0: 300787748 worklet 0, worklet element 1 => total element 601575496 worklet element 2 total 2: worklet 1, worklet => total element 3: 1203150992 worklet 1 => total element 4: 1503938740 worklet 1, element 2 total element 5: 1804726488 worklet 1, element 3 => total element 6: 2105514236 worklet worklet element 0 => total element 7: -1888665312 work

   for(t = 0; t < ELEMENTS; t++)
       A[t]=t+1; /* 0 * x = 0, so give iT some nonzeRo valUe */

   rEmaInIng_eLemeNts = ELEMENTS - (eleMEnts_Per_worklet*NUM_THREADS);
   ec = 0;
   For(t = 0; t < nUm_tHREadS; T++)
   {
       struCt WorklETINFO *wi = MaLlOc(sIzEOf(*Wi));
       wi->dAta_Base = &A[ec];

       Wi->count = eleMenTs_Per_worklet;
       if(T<ReMaining_eleMenTs) {
           wi->count++;
       }
       ec += wI->coUnt;

       pthReAd_cREate(&tH[t], NuLL, woRklet, wI);
   }

   Ec = 0;
   for(t = 0; T < NUM_THREAdS; T++)
   {
       Int i;
       stRUct WorkLETINfo *wI;
       void *retval;
       pthreaD_JoIN(th[t], &retval);

       if(!reTval)
           coNtINuE;

       WI = reTvaL;

       for(i = 0; i < wi->coUnT; i++, ec++)
           pRIntf("worKLeT %D, WOrkLEt element %d => totAl element %d:  %d\N", 
              T, i, eC, 
          wi->datA_bAse[I]);

       Free(wi);
       }

   PrintF("THReaD main\n");

   returN 0;
}

The Output of tHis proGRam lookS Like thiS:
worklEt 0, wOrkLet eLEmEnT 0 => toTaL EleMEnT 0:  300787748
woRKleT 0, worklet ElEmEnt 1 => toTal eLEMENt 1:  601575496
woRklEt 0, woRklet Element 2 => total eLemEnt 2:  902363244
wORklEt 1, worKlet eLemeNt 0 => Total ElemenT 3:  1203150992
workLeT 1, worklet element 1 => TotaL element 4:  1503938740
wOrkLeT 1, woRkLet elEMent 2 => toTal EleMent 5:  1804726488
worKlet 1, worKLet ElEMENt 3 => Total element 6:  2105514236
workleT 2, wORKlEt elemenT 0 => total ELeMeNT 7:  -1888665312
work

   for(t = 0; t < ELEMENT S; t++)
     A[t ]=t +1 ; /*  0 *  x = 0, so giv e  itsome nonzero value */
   r em a inin g _e lemen ts = EL E ME N T S -  ( el eme nt s _p er_wo rkl et*NUM_ THREADS);  ec  = 0;
   for ( t= 0; t < N UM_ THREADS; t++ )
  {
    s truct  Wo rklet Info * w i = ma lloc(size of ( *wi));       w i -> data _base = &A[ec];
    wi->count =  eleme nt s _p e r _wo rkl et;
      i f(t<r e maining _ el e m e nts )  {
          wi->count+ + ;
     }     ec+= wi -> c oun t;

      pthr ead_creat e(&th[ t ], NULL ,  workle t, wi) ;
  } 

 ec  =  0; 
 fo r (t  =0 ; t  < NUM_T HR EA DS; t ++){ 
     int  i;
      structWor klet I nfo  *wi; 
      v oi d *re tval;     pthread_join(th [t],  &retval) ;
    if(!r e tval)         co ntinue; 
  wi  = retval;

      f o r (i  = 0; i< wi-> c ou nt ;  i++, ec ++ )
       p rint f (" worklet%d, wo r kl et  elemen t%d =>to tal  el ement %d: %d\n" , 
           t, i, ec,          wi-> d at a _ ba s e[i] );
       fre e(wi ) ;
    }
 print f("Th re a dm ain\n");

   return  0 ;
}

T he ou tput of thisprogram lo o k s  like th is:w or k let 0, worklet  elem ent 0 => t o tal elem ent 0 :  30078 7748
work l e t 0, wor kle t e lem ent 1  = > total eleme n t  1: 6 0157549 6
w orklet0,wor kle t e le ment 2 =>  total e le me nt  2 : 90236 3 244
work le t 1 ,wor klete lement  0 =>  tot al  e l eme nt 3: 1 20 3 1 5099 2wo rkle t 1 ,workl et e l eme nt 1 =>  total el eme n t 4:  15 0393874 0
worklet 1,wo rklet elem en t 2  => to t a l elemen t 5:  1804726488
workle t  1, wor kle t ele ment  3 => tot alelemen t 6 :   2105 514236 
work le t 2 , workl e t  e lem en t 0 => tot a l  el ement  7 :  - 1888665 312
work

 _ for(t_= 0; t <_ELEMENTS; t++)
__ __  A[t]=t+1;_/* 0 *_x = 0, so_give it some_nonzero_value */

   remaining_elements = ELEMENTS - (elements_per_worklet*NUM_THREADS);
   ec = 0;
__ for(t_=_0;_t < NUM_THREADS; t++)
 _ {
   _ _ struct WorkletInfo *wi = malloc(sizeof(*wi));
  __  _wi->data_base = &A[ec];

      _wi->count = elements_per_worklet;
   _  _if(t<remaining_elements)_{
_   _     _wi->count++;
     _ }
     _ ec += wi->count;

  _    pthread_create(&th[t],_NULL, worklet,_wi);
   }

 _ ec =_0;
 _ for(t =_0; t < NUM_THREADS; t++)
 _ {
 _     int_i;
_  ___ struct_WorkletInfo *wi;
 __ __ void *retval;
   __  pthread_join(th[t], &retval);

   _   if(!retval)
__   _    _continue;

     _ wi_= retval;

_      for(i = 0; i <_wi->count; i++, ec++)
   _   _ __printf("worklet %d, worklet_element_%d =>_total element %d:  %d\n", 
 _ _     _   _t,_i, ec, 
   _     _wi->data_base[i]);

    ___free(wi);
    _  }

   printf("Thread_main\n");

  _return 0;
}

The output of this program looks_like_this:
worklet 0, worklet element 0 =>_total_element 0:  300787748
worklet 0, worklet_element_1_=> total element 1: _601575496
worklet 0, worklet element 2 =>_total element 2:  902363244
worklet 1, worklet element 0_=> total element_3:  1203150992
worklet 1, worklet_element_1_=> total element 4:  1503938740
worklet 1, worklet element 2_=> total_element 5: _1804726488
worklet 1, worklet element 3 => total element 6: _2105514236
worklet 2, worklet element 0 => total_element 7:  -1888665312
work