Beispiel #1
0
/* =============================================================================
 * work
 * =============================================================================
 */
static void
work (void* argPtr)
{
    TM_THREAD_ENTER();

    args_t* args = (args_t*)argPtr;
    float** feature         = args->feature;
    int     nfeatures       = args->nfeatures;
    int     npoints         = args->npoints;
    int     nclusters       = args->nclusters;
    int*    membership      = args->membership;
    float** clusters        = args->clusters;
    int**   new_centers_len = args->new_centers_len;
    float** new_centers     = args->new_centers;
    float delta = 0.0;
    int index;
    long i;
    int j;
    int start;
    int stop;
    int myId;

    myId = thread_getId();

    start = myId * CHUNK;

    while (start < npoints) {
        stop = (((start + CHUNK) < npoints) ? (start + CHUNK) : npoints);
        for (i = start; i < stop; TMHT_LOCAL_WRITE(i, i+1)) {

            index = common_findNearestPoint(feature[i],
                                            nfeatures,
                                            clusters,
                                            nclusters);
            /*
             * If membership changes, increase delta by 1.
             * membership[i] cannot be changed by other threads
             */
            if (membership[i] != index) {
                delta += 1.0;
            }

            /* Assign the membership to object i */
            /* membership[i] can't be changed by other thread */
            membership[i] = index;

            /* Update new cluster centers : sum of objects located within */
            TM_BEGIN();
            TM_SHARED_WRITE_I(*new_centers_len[index],
                              TM_SHARED_READ_I(*new_centers_len[index]) + 1);
            for (j = 0; j < nfeatures; j++) {
                TM_SHARED_WRITE_F(
                    new_centers[index][j],
                    (TM_SHARED_READ_F(new_centers[index][j]) + feature[i][j])
                );
            }
            TM_END();
        }

        /* Update task queue */
        if (start + CHUNK < npoints) {
            TM_BEGIN();
            start = (int)TM_SHARED_READ_L(global_i);
            TM_SHARED_WRITE_L(global_i, (long)(start + CHUNK));
            TM_END();
        } else {
            break;
        }
    }

    TM_BEGIN();
    TM_SHARED_WRITE_F(global_delta, TM_SHARED_READ_F(global_delta) + delta);
    TM_END();

    TM_THREAD_EXIT();
}
Beispiel #2
0
/* =============================================================================
 * work
 * =============================================================================
 */
static void
work (void* argPtr)
{
    
  TM_THREAD_ENTER();

    args_t* args = (args_t*)argPtr;
    float** feature         = args->feature;
    int     nfeatures       = args->nfeatures;
    int     npoints         = args->npoints;
    int     nclusters       = args->nclusters;
    int*    membership      = args->membership;
    float** clusters        = args->clusters;
    long long int**   new_centers_len = args->new_centers_len;
    float** new_centers     = args->new_centers;
    float delta = 0.0;
    int index;
    int i;
    int j;
    int start;
    int stop;
    int myId;
    bool indexx[1000];

    myId = thread_getId();

    start = myId * CHUNK;
    int cnt=0;
    while (start < npoints) {
      stop = (((start + CHUNK) < npoints) ? (start + CHUNK) : npoints);
        for (i = start; i < stop; i++) {

            index = common_findNearestPoint(feature[i],
                                            nfeatures,
                                            clusters,
                                            nclusters);
            /*
             * If membership changes, increase delta by 1.
             * membership[i] cannot be changed by other threads
             */
            if (membership[i] != index) {
                delta += 1.0;
            }

            /* Assign the membership to object i */
            /* membership[i] can't be changed by other thread */
            membership[i] = index;

            /* Update new cluster centers : sum of objects located within */
            TM_BEGIN();
	    //printf("shared write to begin: \n");
	    //	    int write = *new_centers_len[index];
	    //int* pt = new_centers_len[i];
	    //int dat = TM_SHARED_READ_I(*new_centers_len[i]);
	    //printf("in loop write centers lendata: %i %i\n", dat, *new_centers_len[i]);

	    
            TM_SHARED_WRITE_I(*new_centers_len[index],
                            TM_SHARED_READ_I(*new_centers_len[index]) + 1);
	    
	    //printf("befor loop len P: %p data: %i\n", new_centers_len[index], *new_centers_len[index]);
	    //new *new_centers_len[index] = *new_centers_len[index] + 1;
	    //printf("INDEX %i \n" , index);
	    indexx[index] = true;
	    /*if(*new_centers_len[index]==0)*/
	    //printf("in   lloop len P: %p data: %i\n", new_centers_len[index], *new_centers_len[index]);
         	    
	    //*new_centers_len[i] = *new_centers_len[i]+1;
	    //	    pt = new_centers_len[i];
	    //dat = TM_SHARED_READ_I(*new_centers_len[i]);
	    //printf("in loop write centers len data: %i\n", dat);
         
            for (j = 0; j < nfeatures; j++) {
	      //printf("featurs\n");
	      //int feat = feature[i][j];
	      //printf("write\n");
	      //float read = TM_SHARED_READ_F(new_centers[index][j]);
	       
	      //printf("write %p " ,write);
	      //printf("shared write to:\n");
	      //printf("feature %f", feature[i][j]);
	      //float feat = feature[i][j];
	      //float fl = (TM_SHARED_READ_F(new_centers[index][j])+ feat);//feature[i][j]);
	      //int len = *new_centers_len[index];
               
	      
	      TM_SHARED_WRITE_F(
				  //write,
				  new_centers[index][j],
				  //(read + feat)
				  //fl
				  (TM_SHARED_READ_F(new_centers[index][j])+ feature[i][j])
		    //printf("index      %p %p\n", (void*)*new_centers[index][j], (void*)(*new_centers[index][j] +1));
		    //printf("indexnon p %p %p\n", (void*)new_centers[index][j], (void*)(new_centers[index][j] +1));

		    );
	      //new new_centers[index][j] = new_centers[index][j] + feature[i][j];
		
		//if(0==*new_centers_len[index]) printf("ISNAN %i\n", len);
		//if(isnanf(new_centers[index][j])) printf("ISNAN2\n\n");

		//		if(isinf(*new_centers_len[index])) printf("ISINF\n\n");
		//if(isinf(*new_centers_len[index])) printf("ISINF2\n\n");
            }
            TM_END();
        }
	//printf("update \n");
        /* Update task queue */
	if (start + CHUNK < npoints) {
	  TM_BEGIN();
	  start = (int)TM_SHARED_READ_L(*global_i);
	  TM_SHARED_WRITE_L(*global_i, (long)(start + CHUNK));
	  TM_END();
        } else {
            break;
        }
    }

    TM_BEGIN();
    //printf("shared write to: %p", *global_delta);
    TM_SHARED_WRITE_F(*global_delta, TM_SHARED_READ_F(*global_delta) + delta);
    //new *global_delta = *global_delta + delta;
    TM_END();
    int u1 =0;
    /* for(int i1=0; i1<1000; i1++){
      if(indexx[i1]) printf("INDEX %i %i\n", i1, u1++);
    }*/
    TM_THREAD_EXIT();
}