Esempio n. 1
0
static 
void 
doTransaction_T5(Ndb * pNDB, ThreadData * td, int async)
{
  SessionElement * se;
  se = getNextSession(&td->generator.activeSessions);
  if( se ) {
    strcpy(td->transactionData.number, se->subscriberNumber);
    td->transactionData.server_id = se->serverId;
    td->transactionData.sessionElement = 1;
  }
  else {
    getRandomSubscriberNumber(td->transactionData.number);
    getRandomServerId(&td->transactionData.server_id);
    td->transactionData.sessionElement = 0;
  }
  
  td->transactionData.server_bit = (1 << td->transactionData.server_id);
  td->transactionData.do_rollback  
    = getNextRandom(&td->generator.rollbackSequenceT5);
  
  /*-----------------*/
  /* Run transaction */
  /*-----------------*/
  td->runState = Running;
  td->generator.transactions[4].startLatency();
  start_T5(pNDB, td, async);
}
Esempio n. 2
0
static 
void 
doTransaction_T4(Ndb * pNDB, ThreadData * td, int async)
{
   /*----------------*/
   /* Init arguments */
   /*----------------*/
  getRandomSubscriberNumber(td->transactionData.number);
  getRandomServerId(&td->transactionData.server_id);
  
  td->transactionData.server_bit = (1 << td->transactionData.server_id);
  td->transactionData.do_rollback = 
    getNextRandom(&td->generator.rollbackSequenceT4);

#if 0
  memset(td->transactionData.session_details, 
	 myRandom48(26)+'A', SESSION_DETAILS_LENGTH);
#endif
  td->transactionData.session_details[SESSION_DETAILS_LENGTH] = 0;
  
  /*-----------------*/
  /* Run transaction */
  /*-----------------*/
  td->runState = Running;
  td->generator.transactions[3].startLatency();
  start_T4(pNDB, td, async);
}
Esempio n. 3
0
static 
void 
doOneTransaction(ThreadData * td, int p, int millis, int minEvents, int force)
{
  int i;
  unsigned int transactionType;
  int async = 1;
  if (p == 1) {
    async = 0;
  }//if
  for(i = 0; i<p; i++){
    if(td[i].runState == Runnable){
      transactionType = getNextRandom(&td[i].generator.transactionSequence);

      switch(transactionType) {
      case 1:
	doTransaction_T1(td[i].pNDB, &td[i], async);
	break;
      case 2:
	doTransaction_T2(td[i].pNDB, &td[i], async);
	break;
      case 3:
	doTransaction_T3(td[i].pNDB, &td[i], async);
	break;
      case 4:
	doTransaction_T4(td[i].pNDB, &td[i], async);
	break;
      case 5:
	doTransaction_T5(td[i].pNDB, &td[i], async);
	break;
      default:
	ndbout_c("Unknown transaction type: %d", transactionType);
      }
    }
  }
  if (async == 1) {
    td[0].pNDB->sendPollNdb(millis, minEvents, force);
  }//if
}  
Esempio n. 4
0
File: ra.c Progetto: AbheekG/chapel
int main(int argc, char* argv[]) {
  unsigned long long i, locN_U, locStart, locEnd;
  rndtype r, recvBuf[2];
  MPI_Request recvReq;
  int base, iter, errorCnt = 0, totalErrors;
  double starttime, finishtime, exectime;

  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &nprocs);

  parseArgs(argc, argv);

  if (rank == 0) {
    printf("Number of nodes = %d\n", nprocs); fflush(stdout);
    printf("Problem size = %lld (2**%d)\n", m, n); fflush(stdout);
    printf("Number of updates = %lld (2**%d)\n", N_U, N_U_log2); fflush(stdout);
  }
  randInit();

  A = malloc(sizeof(rndtype)*m/nprocs);
  if (A == NULL) {
    printf("malloc failed for main array.\n"); fflush(stdout);
    MPI_Abort(MPI_COMM_WORLD, 1);
  }
  
  base = rank * (m / nprocs);
  for (i=0; i < m / nprocs; i++) {
    A[i] = i + base;
  }

  MPI_Barrier(MPI_COMM_WORLD);
  // first iteration does the benchmark, second reverses it for validation.
  for (iter=0; iter < 2; iter++) {
    doneCount = 0;
    doneWithRecvs = 0;

    if (iter == 0) {
      starttime = now_time();
    }

    MPI_Irecv(recvBuf, 2*sizeof(rndtype), MPI_BYTE, MPI_ANY_SOURCE, 1, MPI_COMM_WORLD, &recvReq);

    locN_U = N_U / nprocs;
    locStart = locN_U * rank;
    locEnd = locStart+locN_U;
    r = getNthRandom(locStart);
    for (i=locStart; i < locEnd; i++) {
      int loc = idxToLocale(r & idxMask);
      if (loc < 0 || loc > nprocs-1) {
        printf("error: r=%llu, r&mask=%llu, loc=%d\n", r, r&idxMask, loc);
      }
      if (loc == rank) {
        A[ind2localIdx(r & idxMask)] ^= r;
      } else {
        dosend(loc, r, 0, &recvReq, recvBuf);
      }
      getNextRandom(&r);
    }
    for (i = 0; i < nprocs; i++) {
      dosend(i, 0, 1, &recvReq, recvBuf);
    }
    while (!doneWithRecvs) {
      tryRecv(&recvReq, recvBuf);
    }

    MPI_Barrier(MPI_COMM_WORLD);
    if (iter == 0) {
      finishtime = now_time();
      exectime = (finishtime - starttime) / 1.0e+6;
    }
  }

  for (i=0; i < m/nprocs; i++) {
    if (A[i] != i + base) {
      errorCnt++;
    }
  }

  MPI_Reduce(&errorCnt, &totalErrors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);

  if (rank == 0) {
    printf("Number of errors: %d\n", totalErrors); fflush(stdout);
    if (totalErrors <= errorTolerance * N_U) {
      printf("Validation: SUCCESS\n"); fflush(stdout);
    } else {
      printf("Validation: FAILURE\n"); fflush(stdout);
    }
    printf("Execution time = %lf\n", exectime); fflush(stdout);
    printf("Performance (GUPS) = %lf\n", (N_U / exectime) * 1.0e-9); fflush(stdout);
  }

  MPI_Finalize();

  return 0;
}
Esempio n. 5
0
int writeDataToImage(IplImage *img, PixelMap *pixelmap, FILE *file, ConfigInfo config, unsigned int useable_pixels)
{

	CvScalar pixel;
	int index, number;
	int i,j, written_bytes=0;
	int message_length;
	unsigned int img_capacity;
	char byte;

	int img_channels = 0;

	if(img->nChannels == 1)
	{
		img_channels = 1;
	}
	if(img->nChannels >= 3){
		img_channels = 3;
	}

	img_capacity = (unsigned int)( ((useable_pixels * img_channels) - MESSAGE_LENGTH_BITS) / BYTE );

	message_length = getFileLength(file);

	if(img_capacity < message_length)
	{
		printf("Image capacity is only: %u Byte -> message size is: %d\n", img_capacity, message_length);
		return 0;
	}

	printf("Image capacity is: %u Byte\n", img_capacity);
	printf("Message size is: %d Byte\n", message_length);


	DEBUG( ("writing message length bits to image\n") );

	for(i=MESSAGE_LENGTH_BITS-1; i>=0; )
	{

		//get next free pixel
		do
		{
			number = getNextRandom();

			index = number % useable_pixels;
		}
		while( pixelmap[index].used == TRUE );

		//get values at this place
		pixel = cvGet2D(img, pixelmap[index].x_coord, pixelmap[index].y_coord);


		//if we have more than one channel
		for(j=0; j<img_channels; j++)
		{
			pixel.val[j] = LSB_BIT( (int)pixel.val[j],  ((message_length >> i) & 1) );

			DEBUG( ("%u", ((message_length >> i) & 1)) );

			i--;

			if(i < 0)
			{
				break;
			}
		}

		cvSet2D(img, pixelmap[index].x_coord, pixelmap[index].y_coord, pixel);

		pixelmap[index].used = TRUE;

	}
	DEBUG( ("\n") );

	getNextRandom();//fix -> asynchron


	/////////////////////////////////////////////////////////////////////////////
	DEBUG( ("writing bytes to image...") );

	j=3;

	while( (EOF != (byte = getByteFromFile(file))) && (written_bytes < img_capacity) && (written_bytes < message_length) )
	{

		for(i=BYTE-1; i>=0; )
		{
			if(j>=img_channels)
			{
				j=0;

				do
				{
					number = getNextRandom();

					index = number % useable_pixels;
				}
				while( pixelmap[index].used == TRUE );

				pixel = cvGet2D(img, pixelmap[index].x_coord, pixelmap[index].y_coord);
			}
			else
			{
				j++;
			}


			while(j<img_channels)
			{
				pixel.val[j] = LSB_BIT( (int)pixel.val[j],  ((byte >> i) & 1) );

				i--;

				if(i < 0)
				{
					break;
				}

				j++;
			}

			cvSet2D(img, pixelmap[index].x_coord, pixelmap[index].y_coord, pixel);

			pixelmap[index].used = TRUE;
		}

		written_bytes++;

	}
	DEBUG( ("done\n") );


	printf("%d Bytes written to image\n", written_bytes);


	return written_bytes;
}
Esempio n. 6
0
int readDataFromImage(IplImage *img, PixelMap *pixelmap, FILE *file, ConfigInfo config, unsigned int useable_pixels)
{
	CvScalar pixel;
	int index, number;
	int i,j;
	unsigned int message_length=0;
	unsigned int img_capacity;
	unsigned int extracted_bytes=0;
	char byte=0;

	int img_channels = 0;

	if(img->nChannels == 1)
	{
		img_channels = 1;
	}
	if(img->nChannels >= 3){
		img_channels = 3;
	}

	img_capacity = (unsigned int)( ((useable_pixels * img_channels) - MESSAGE_LENGTH_BITS) / BYTE );

	printf("Image capacity is: %u Byte\n", img_capacity);


	initFile(file);


	DEBUG( ("extracting message size bits \n") );

	for(i=0; i<=MESSAGE_LENGTH_BITS; )
	{

		//get next free pixel
		do
		{
			number = getNextRandom();

			index = number % useable_pixels;
		}
		while( pixelmap[index].used == TRUE );

		//get values at this place
		pixel = cvGet2D(img, pixelmap[index].x_coord, pixelmap[index].y_coord);

		//if we have more than one channel
		for(j=0; j<img_channels; j++)
		{
			message_length |= (int)pixel.val[j] & 1;

			i++;

			if(i < MESSAGE_LENGTH_BITS)
			{
				message_length <<= 1;
			}
			else
			{
				break;
			}

			DEBUG( ("%u", ((int)pixel.val[j] & 1) ) );
		}

		pixelmap[index].used = TRUE;

	}
	DEBUG( ("\n") );

	if(message_length > img_capacity)
	{
		printf("The embedded message size (%d) does not fix to image's capacity (%d)\n", message_length, img_capacity);
		printf("Please check if you have chosen the correct parameters and password\n");
		return 0;
	}

	printf("Integrated message size is: %d Byte\n", message_length);


	////////////////////////////////////////////////////////////////////////////////////////
	DEBUG( ("extracting bytes out of image...") );

	j=3;

	while( extracted_bytes < message_length )
	{
		byte=0;

		for(i=0; i<BYTE; )
		{

			if(j>=img_channels)
			{
				j=0;

				do
				{
					number = getNextRandom();

					index = number % useable_pixels;
				}
				while( pixelmap[index].used == TRUE );

				pixel = cvGet2D(img, pixelmap[index].x_coord, pixelmap[index].y_coord);
			}
			else
			{
				j++;
			}


			while(j<img_channels)
			{
				byte |= (int)pixel.val[j] & 1;

				i++;

				if(i < BYTE)
				{
					byte <<= 1;
				}
				else
				{
					break;
				}

				j++;
			}

			pixelmap[index].used = TRUE;
		}

		writeByteToFile(file, byte);

		extracted_bytes++;

	}
	DEBUG( ("done\n") );


	printf("%d Bytes extracted from image\n", extracted_bytes);


	return extracted_bytes;
}