Beispiel #1
0
static UserData AllocUserData(void)
{
  int jx, jy;
  UserData data;

  data = (UserData) malloc(sizeof *data);

  for (jx=0; jx < MX; jx++) {
    for (jy=0; jy < MY; jy++) {
      (data->P)[jx][jy] = newDenseMat(NUM_SPECIES, NUM_SPECIES);
      (data->Jbd)[jx][jy] = newDenseMat(NUM_SPECIES, NUM_SPECIES);
      (data->pivot)[jx][jy] = newIntArray(NUM_SPECIES);
    }
  }

  return(data);
}
Beispiel #2
0
static UserData AllocUserData(void)
{
  int jx, jy;
  UserData data;

  data = (UserData) malloc(sizeof *data);
  
  for (jx=0; jx < MX; jx++) {
    for (jy=0; jy < MY; jy++) {
      (data->P)[jx][jy] = newDenseMat(NUM_SPECIES, NUM_SPECIES);
      (data->pivot)[jx][jy] = newIntArray(NUM_SPECIES);
    }
  }
  acoef = newDenseMat(NUM_SPECIES, NUM_SPECIES);
  bcoef = (realtype *)malloc(NUM_SPECIES * sizeof(realtype));
  cox   = (realtype *)malloc(NUM_SPECIES * sizeof(realtype));
  coy   = (realtype *)malloc(NUM_SPECIES * sizeof(realtype));
  
  return(data);
}
Beispiel #3
0
static UserData AllocUserData(MPI_Comm comm, int local_N, int SystemSize)
{
  int ix, jy;
  UserData webdata;
  
  webdata = (UserData) malloc(sizeof *webdata);
  
  webdata->rates = N_VNew_Parallel(comm, local_N, SystemSize);
  
  for (ix = 0; ix < MXSUB; ix++) {
    for (jy = 0; jy < MYSUB; jy++) {
      (webdata->PP)[ix][jy] = newDenseMat(NUM_SPECIES, NUM_SPECIES);
      (webdata->pivot)[ix][jy] = newIntArray(NUM_SPECIES);
    }
  }
  
  webdata->acoef = newDenseMat(NUM_SPECIES, NUM_SPECIES);
  webdata->ewt = N_VNew_Parallel(comm, local_N, SystemSize);
  return(webdata);
  
}
Beispiel #4
0
static int fastBlur(int radius, unsigned char* srcRed, unsigned char* srcGreen, unsigned char* srcBlue, int width, int height, unsigned char* dstRed, unsigned char* dstGreen, unsigned char* dstBlue) {
	int windowSize = radius * 2 + 1;
	int radiusPlusOne = radius + 1;

	int sumRed;
	int sumGreen;
	int sumBlue;

	int srcIndex = 0;
	int dstIndex;

	int sumLookupTableSize = 256 * windowSize;
	int* sumLookupTable;
	int returnCode = newIntArray(sumLookupTableSize, &sumLookupTable);
	if (returnCode != MEMORY_OK) {
		return returnCode;
	}

	int i;
	for (i = 0; i < sumLookupTableSize; i++) {
		sumLookupTable[i] = i / windowSize;
	}

	int* indexLookupTable;
	returnCode = newIntArray(radiusPlusOne, &indexLookupTable);
	if (returnCode != MEMORY_OK) {
		free(sumLookupTable);
		return returnCode;
	}

	if (radius < width) {
		for (i = 0; i < radiusPlusOne; i++) {
			indexLookupTable[i] = i;
		}
	} else {
		for (i = 0; i < width; i++) {
			indexLookupTable[i] = i;
		}
		for (i = width; i < radiusPlusOne; i++) {
			indexLookupTable[i] = width - 1;
		}
	}

	int x, y;
	for (y = 0; y < height; y++) {
		sumRed = sumGreen = sumBlue = 0;
		dstIndex = y;


		sumRed += radiusPlusOne * srcRed[srcIndex];
		sumGreen += radiusPlusOne * srcGreen[srcIndex];
		sumBlue += radiusPlusOne * srcBlue[srcIndex];

		for (i = 1; i <= radius; i++) {
			sumRed += srcRed[srcIndex + indexLookupTable[i]];
			sumGreen += srcGreen[srcIndex + indexLookupTable[i]];
			sumBlue += srcBlue[srcIndex + indexLookupTable[i]];
		}

		for (x = 0; x < width; x++) {
			dstRed[dstIndex] = sumLookupTable[sumRed];
			dstGreen[dstIndex] = sumLookupTable[sumGreen];
			dstBlue[dstIndex] = sumLookupTable[sumBlue];
			dstIndex += height;

			int nextPixelIndex = x + radiusPlusOne;
			if (nextPixelIndex >= width) {
				nextPixelIndex = width - 1;
			}

			int previousPixelIndex = x - radius;
			if (previousPixelIndex < 0) {
				previousPixelIndex = 0;
			}

			sumRed += srcRed[srcIndex + nextPixelIndex];
			sumRed -= srcRed[srcIndex + previousPixelIndex];

			sumGreen += srcGreen[srcIndex + nextPixelIndex];
			sumGreen -= srcGreen[srcIndex + previousPixelIndex];

			sumBlue += srcBlue[srcIndex + nextPixelIndex];
			sumBlue -= srcBlue[srcIndex + previousPixelIndex];
		}

		srcIndex += width;
	}

	free(sumLookupTable);
	free(indexLookupTable);

	return MEMORY_OK;
}