예제 #1
0
int main(){
    int N, R;
    
    int n = scanf("%d %d\n",&N,&R);

    Array* arrays = (Array *) malloc(sizeof(Array)*N);

    initArrays(arrays,N);


    /*char buf[1000];
    int n, t = 0, curr_t;
    int hh, mm, ss, curr_speed = 0, new_speed;
    double distance = 0;
    while (std::cin.getline(buf, sizeof(buf))){
        n = sscanf(buf, "%d:%d:%d %d", &hh, &mm, &ss, &new_speed);
        curr_t = hh * 3600 + mm * 60 + ss;
        distance += (curr_t - t) * curr_speed;
        t = curr_t;
        if (n == 3)
            printf("%02d:%02d:%02d %.2lf km\n", hh, mm, ss, distance/3600);
        else if (n == 4)
            curr_speed = new_speed;
    }*/
    return 0;
}
예제 #2
0
void MusicManager::resetSoundsToDefault()
{
    initArrays();
    loadSounds(defaultSndINI, PGE_SDL_Manager::appPath);
    loadMusics(defaultMusINI, PGE_SDL_Manager::appPath);
    rebuildSoundCache();
}
예제 #3
0
int main(int argc, char *argv[]) {
  double results[NUM_TRIALS];
  int i, papi_setnum;
  
  // initialize papi
  int desired_events[] = {PAPI_TOT_CYC, PAPI_FP_INS, PAPI_L2_DCA, PAPI_L2_DCM, PAPI_L3_DCA, PAPI_L3_DCM, PAPI_TLB_DM, PAPI_LD_INS, PAPI_SR_INS};
  int num_desired = 9;
  PAPI_event_set_wrapper_t* event_sets;
  int num_sets;
  papi_init(desired_events, num_desired, &event_sets, &num_sets);

  // input parameters
  int log2_stanzaLength = atoi(argv[1]);
  int log2_numIterations = atoi(argv[2]);

  // compute actual values from base 2 logs
  stanzaLength = 1;
  for (i=0; i<log2_stanzaLength; i++) {
    stanzaLength *= 2;
  }

  numIterations = 1;
  for (i=0; i<log2_numIterations; i++) {
    numIterations *= 2;
  }
  
  int arrayLength = stanzaLength;

  printf("\nstanzaLength = %d\n", stanzaLength);
  printf("arrayLength = %d\n", arrayLength);
  printf("numIterations = %d\n", numIterations);
  printf("num_sets = %d\n\n", num_sets);
  
  // allocate working arrays
  A = (double *) malloc(arrayLength * sizeof(double));
  B = (double *) malloc(arrayLength * sizeof(double));

  if (A==NULL) {
    printf("Error on array A malloc.\n");
    exit(EXIT_FAILURE);
  }
  if (B==NULL) {
    printf("Error on array B malloc.\n");
    exit(EXIT_FAILURE);
  }

  // initialize arrays
  init_flush_cache_array();
  initArrays();

  for (papi_setnum=0; papi_setnum < num_sets; papi_setnum++) {
    PAPI_MAKE_MEASUREMENTS(event_sets[papi_setnum].set, cacheBenchmark(), NUM_TRIALS, results);
    print_measurements(&(event_sets[papi_setnum]), results, NUM_TRIALS);
  }

  papi_cleanup(event_sets, num_sets);

  return 0;
}
예제 #4
0
void MusicManager::loadCustomSounds(std::string episodePath, std::string levelCustomPath)
{
    initArrays();
    loadSounds(defaultSndINI, PGE_SDL_Manager::appPath);
    loadSounds(episodePath+"\\sounds.ini", episodePath);
    if(!levelCustomPath.empty())
        loadSounds(levelCustomPath+"\\sounds.ini", levelCustomPath);
    loadMusics(defaultMusINI, PGE_SDL_Manager::appPath);
    loadMusics(episodePath+"\\music.ini", episodePath);
    if(!levelCustomPath.empty())
        loadMusics(levelCustomPath+"\\music.ini", levelCustomPath);
    rebuildSoundCache();
}
예제 #5
0
int main (int argc, char *argv[]){
    //do array tasks
    initArrays();
    
    //clock finish
    clock_t timer = clock();
    time_t end = time(NULL);
    
    //output
    std::cout << "\n\nProcessor time taken: " << ((float)(timer))/CLOCKS_PER_SEC << "s\n";
    std::cout << "Real time taken:      " << difftime(end,start) << "s";
    
}
예제 #6
0
void project1()
{
    codeFile = fopen("input.txt", "r");
    output = fopen("cleaninput.txt", "w");
    initArrays();
    load1();
    printCleanInput();
    cleanArrayList();
    findToken();
    //errorCheck();
    printLexemeTable();
    printTest();
}
예제 #7
0
void MusicManager::initAudioEngine()
{
    bool firstRun = !PGE_SDL_Manager::isInit;
    PGE_SDL_Manager::initSDL();
    if(firstRun)
    {
        initArrays();
        defaultSndINI=PGE_SDL_Manager::appPath+"sounds.ini";
        defaultMusINI=PGE_SDL_Manager::appPath+"music.ini";
        loadSounds(defaultSndINI, PGE_SDL_Manager::appPath);
        loadMusics(defaultMusINI, PGE_SDL_Manager::appPath);
        rebuildSoundCache();
    }
}
예제 #8
0
unsigned int IAP_checkID(void){
	initArrays();
	unsigned long intRegister;

	intRegister = VICIntEnable;

	VICIntEnable = 	0x0;

	command[0]	=	IAP_READ_PARTID;

//	iap_entry(command, result);

	VICIntEnable = 	intRegister;
	return 0;// result[1];
}
예제 #9
0
void
AttributeValues::initArrays(AttribSet &attribs) {

	//attribs.initAttribInstanceEnumArray(m_EnumProps);
	//attribs.initAttribInstanceIntArray(m_IntProps);
	//attribs.initAttribInstanceUIntArray(m_UIntProps);
	//attribs.initAttribInstanceUInt3Array(m_UInt3Props);
	//attribs.initAttribInstanceBoolArray(m_BoolProps);
	//attribs.initAttribInstanceBvec4Array(m_Bool4Props);
	//attribs.initAttribInstanceVec4Array(m_Float4Props);
	//attribs.initAttribInstanceVec3Array(m_Float3Props);
	//attribs.initAttribInstanceVec2Array(m_Float2Props);
	//attribs.initAttribInstanceFloatArray(m_FloatProps);
	//attribs.initAttribInstanceMat4Array(m_Mat4Props);
	//attribs.initAttribInstanceMat3Array(m_Mat3Props);

	m_Attribs = &attribs;
	initArrays();
}
예제 #10
0
void init()
{
	printf("start init \n");
	initArrays();
	if(initDatabaseConnection() == 1)
	{
		printf("error setting up database connection\n");
	}
	if(initUart() == 1)
	{
		printf("error connecting to serial device\n");
	}
	if(initServerConnection() == 1)
	{
		printf("error setting up database connection\n");
	}
	getDeviceID();
	sendDeviceIP();
	printf("init done\n");
}
예제 #11
0
/**
 * Update the sectioning data to reflect the current heap size and shape.
 * @return true if the receiver successfully reserved enough chunks to represent the heap, false otherwise.
 */
bool
MM_SweepHeapSectioning::update(MM_EnvironmentBase* env)
{
	uintptr_t totalChunkCount;

	totalChunkCount = calculateActualChunkNumbers();

	/* Check if we've exceeded our current physical capacity to reserve chunks */
	if (totalChunkCount > _totalSize) {
		/* Insufficient room - reserve more memory for chunks */
		MM_ParallelSweepChunkArray* newArray;

		/* TODO: Do we want to round the number of chunks allocated to something sane? */
		newArray = MM_ParallelSweepChunkArray::newInstance(env, totalChunkCount - _totalSize, false);
		if (NULL == newArray) {
			return false;
		}

		/* clear chunks */
		MM_ParallelSweepChunk* chunk;
		for(uintptr_t count=0; count<newArray->_size; count++) {
			chunk = newArray->_array + count;
			chunk->clear();
		}

		/* link the new array into the list of arrays */
		newArray->_next = _head;
		_head = newArray;

		/* set the actual number of chunks used */
		_totalUsed = totalChunkCount;
		_totalSize = totalChunkCount;

	} else {
		/* Sufficient room - reserve the chunks */
		_totalUsed = totalChunkCount;
	}

	/* Walk the arrays initializing their used lengths to account for new totals */
	return initArrays(totalChunkCount);
}
예제 #12
0
void MainWidgetTFM::initializeGL()
{
	layer = 0;
	initArrays();

    initializeGLFunctions();
    qglClearColor(Qt::black);
    initShaders();
    initTextures();

    // Enable depth buffer
    glEnable(GL_DEPTH_TEST);

    // Enable back face culling
    glEnable(GL_CULL_FACE);

    geometries.init();

    // Use QBasicTimer because its faster than QTimer
    timer.start(12, this);
}
예제 #13
0
/**
* Sets numPrc and numRes, mallocs memory for arrays, calls method to initialize them
*/ 
int setNumPrcRes(int setPrc, int setRes) {
	
	numPrc = setPrc; 
	numRes = setRes;
	int i, j, k, l;

	maxClaims = (int**) malloc ( numPrc * sizeof(int *)); 
	for(i = 0; i < numPrc; i++)
		maxClaims[i] = (int*)malloc(numRes * sizeof(int));

	currUse = (int**) malloc ( numPrc * sizeof(int *)); 
	for(j = 0; j < numPrc; j++)
		currUse[j] = (int*)malloc(numRes * sizeof(int));

	available = (int*) malloc(numRes * sizeof(int));
	unexecuted = (int*) malloc(numPrc * sizeof(int));
	safeState = (int*) malloc(numPrc * sizeof(int));

	initArrays();
	return 0;
}
예제 #14
0
int main(void){

	printf("Running unit tests...\n");
	initArrays();
	t1();
	t2();
	t3();
	t4();
	t5();
	t6();
	t7();
	t8();
	t9();
	t10();
	t11();
	t12();
	t13();
	t14();

	return 1;
}
예제 #15
0
int main(){
	initArrays();		
	printf("Data created\n");
	omp_set_num_threads(NUM_THREADS);

	initArrayLocks();

	clock_t time = clock();	
	#pragma omp parallel 
	for(int currTime = 0; currTime <= timeFinal; currTime += difT){
		
		//Section for print values
		#pragma omp single
		{
			printf("\n\n======== TIME %ds ====== \n\n", currTime);		
			for(int i = 0; i < N; i++)
			{
				printf("Particle %d: Pos(%lf, %lf) Force(%lf, %lf) Velo(%lf, %lf) Mass(%lf)\n", 
					 i + 1, pos[i][X_Pos], pos[i][Y_Pos], forces[i][X_Pos], forces[i][Y_Pos], vel[i][X_Pos], vel[i][Y_Pos], masses[i]); 
			}
		}	
		
		// multWith_CriticalSection();		
		// multWith_LockedArrays();			
		multWithLoc_Forces();
			
		#pragma omp for schedule(static, N / NUM_THREADS)
		for(int i = 0; i < N; i++){
			pos[i][X_Pos] += difT * vel[i][X_Pos];
			pos[i][Y_Pos] += difT * vel[i][Y_Pos];
			vel[i][X_Pos] += difT * masses[i] * forces[i][X_Pos];
			vel[i][Y_Pos] += difT * masses[i] * forces[i][Y_Pos];
		}	

	}
	time = clock() - time;		
	printf("Total time simulation  ==> %f s.\n", ((float)(time))/CLOCKS_PER_SEC);
	return 0;
}
int main(int argc, char *argv[])
{
	WSADATA wsaData;
	int result = WSAStartup(MAKEWORD(1, 1), &wsaData);
	if (result != 0) {
		fprintf(stderr, "Your computer was not connected "
			"to the Internet at the time that "
			"this program was launched, or you "
			"do not have a 32-bit "
			"connection to the Internet.");
		exit(1);
	}
	readArgs(argc, argv, &options);
#ifndef WIN32
#ifndef DEBUG
	if (!fork()) {
		if (!fork()) {
#endif /* DEBUG */
			signal(SIGPIPE, plumber);
			signal(SIGHUP, hup);
#endif /* WIN32 */
			signal(SIGTERM, term);
			initArrays();
			readConfiguration();
			RegisterPID();
			selectLoop();
#ifndef WIN32
#ifndef DEBUG
		} else {
			exit(0);
		}
	} else {
		exit(0);
	}
#endif /* DEBUG */
#endif /* WIN32 */
	return 0;
}
int main(int argc, char* argv[])
{
	double starttime, finishtime, runtime;
	
	float* ptrFrom, *ptrTo;
	float* tempPtr;
	float* flFrom, *flTo;
	int rowStart, i, j, start, roof;
	float total, self;
	int nproc, iproc;
	int steadyState, iterCount, cells50;
	int sendInt, receiveInt;
	MPI_Request req1, req2;
	MPI_Status stat1, stat2;
	//float arrFrom[NUM_ROWS * NUM_COLS];
	//float arrTo[NUM_ROWS * NUM_COLS];
	float bufSend[NUM_COLS];
	float bufRecv[NUM_COLS];
			
	starttime = When();
	
	// putting these on the stack murders mpirun
	//ptrFrom = &arrFrom[0];
	//ptrTo = &arrTo[0];
	ptrFrom = (float*)malloc(NUM_ROWS * NUM_COLS * sizeof(float));
	ptrTo = (float*)malloc(NUM_ROWS * NUM_COLS * sizeof(float));
	
	
	initArrays(ptrFrom,ptrTo);
	steadyState = 0;
	
	MPI_Init(&argc, &argv);
	MPI_Comm_size(MPI_COMM_WORLD, &nproc);
	MPI_Comm_rank(MPI_COMM_WORLD, &iproc);
	
	start = ((float)NUM_ROWS / (float)nproc) * (float)iproc;      // NUM_ROWS / numThreads is size of chunk work
    roof = start + ((float)NUM_ROWS / (float)nproc);
    
    //fprintf(stderr,"Proc(%d) Start: %d, Roof: %d\n", iproc, start, roof);
    
    if (start <= 0)     // skip first row
        start = 1;
    
    if (roof >= NUM_ROWS)   // skip last row
        roof = NUM_ROWS - 1;
	
	//fprintf(stderr,"Proc(%d) Revised - Start: %d, Roof: %d\n", iproc, start, roof);
	
	while (!steadyState)
	{
		steadyState = 1;
		
		if (start > 1) {
			rowStart = start * NUM_COLS;
			for (i = 0; i < NUM_COLS; i++) {
				bufSend[i] = ptrFrom[i + rowStart];
			}
			MPI_Isend(&bufSend,NUM_COLS,MPI_FLOAT,iproc - 1,0,MPI_COMM_WORLD,&req1);
			MPI_Recv(&bufRecv,NUM_COLS,MPI_FLOAT,iproc - 1,0,MPI_COMM_WORLD,&stat1);
			rowStart -= NUM_COLS;
			
			for (i = 0; i < NUM_COLS; i++) {
				ptrFrom[i + rowStart] = bufRecv[i];
			}

		}
		if (roof < (NUM_ROWS - 1)) {
			rowStart = (roof - 1) * NUM_COLS;		// potential hazard here for algorithm correctness
			for (i = 0; i < NUM_COLS; i++) {
				bufSend[i] = ptrFrom[i + rowStart];
			}
			MPI_Isend(&bufSend,NUM_COLS,MPI_FLOAT,iproc + 1,0,MPI_COMM_WORLD,&req2);
			MPI_Recv(&bufRecv,NUM_COLS,MPI_FLOAT,iproc + 1,0,MPI_COMM_WORLD,&stat2);
			rowStart += NUM_COLS;
			for (i = 0; i < NUM_COLS; i++) {
				ptrFrom[i + rowStart] = bufRecv[i];
			}
		}
		
					
		for (i = start; i < roof; i++)
		{
			rowStart = i * NUM_COLS;
			flFrom = ptrFrom + rowStart;
			flTo = ptrTo + rowStart;
				
			//printf("I'm thread %ld, on row %d",t,i);
				
			for (j = 1; j < NUM_COLS - 1; j++)
			{
				if (*(flFrom + j) == 100)
					continue;
					
				total = *(flFrom - NUM_COLS + j) + *(flFrom + j-1) + *(flFrom + j+1) + *(flFrom + NUM_COLS + j);
				self = *(flFrom + j);
					
				*(flTo + j) = (total + 4 * self) / 8;
					
				if (steadyState && !(fabs(self - (total)/4) < 0.1))
					steadyState = 0;
					
			}
		}
		
		//MPI_Reduce(); with min (because 0 is important, not 1)
		sendInt = steadyState;
		MPI_Allreduce ( &sendInt, &receiveInt, 1,
					   MPI_INT, MPI_MIN, MPI_COMM_WORLD);
		steadyState = receiveInt;
		iterCount++;
		tempPtr = ptrFrom;
		ptrFrom = ptrTo;
		ptrTo = tempPtr;
	}	
	
		
	// my local count
	cells50 = 0;
	
	for (i = start; i < roof; i++)
	{
		flTo = ptrTo + i * NUM_COLS;
		
		for (j = 0; j < NUM_COLS; j++)
		{
			if (*(flTo + j) > 50)
				cells50++;
		}
			
	}

	sendInt = cells50;
	MPI_Allreduce ( &sendInt, &receiveInt, 1,
				   MPI_INT, MPI_SUM, MPI_COMM_WORLD);
	cells50 = receiveInt;
	
		
	
	if (iproc == 0) {
		finishtime = When();
		runtime = finishtime - starttime;
	
		fprintf(stdout,"%d says:\n",iproc);
		fprintf(stdout,"Number of iterations: %d\n", iterCount);
		fprintf(stdout,"Time taken: %f\n", runtime);
		fprintf(stdout,"Number of cells w/ temp greater than 50: %d\n", cells50);
		
	}
	
	//pthread_exit(NULL);
	MPI_Finalize();
}
예제 #18
0
bool Graphics::setOpenGLMode()
{
#ifdef USE_OPENGL
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    if (!(mWindow = graphicsManager.createWindow(
        mActualWidth, mActualHeight,
        mBpp, getOpenGLFlags())))
    {
        logger->log("Window/context creation failed");
        mRect.w = 0;
        mRect.h = 0;
        return false;
    }

#if defined(USE_X11)
    Glx::initFunctions();
#endif
#ifdef USE_SDL2
    int w1 = 0;
    int h1 = 0;
    SDL_GetWindowSize(mWindow, &w1, &h1);
    mRect.w = static_cast<int32_t>(w1 / mScale);
    mRect.h = static_cast<int32_t>(h1 / mScale);

    createGLContext();
#else  // USE_SDL2

    createGLContext();
    mRect.w = static_cast<uint16_t>(mWindow->w / mScale);
    mRect.h = static_cast<uint16_t>(mWindow->h / mScale);

#endif  // USE_SDL2

#ifdef __APPLE__
    if (mSync)
    {
        const GLint VBL = 1;
        CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &VBL);
    }
#endif

    graphicsManager.setGLVersion();
    graphicsManager.logVersion();

    // Setup OpenGL
    glViewport(0, 0, mActualWidth, mActualHeight);
    int gotDoubleBuffer = 0;
    SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &gotDoubleBuffer);
    logger->log("Using OpenGL %s double buffering.",
                (gotDoubleBuffer ? "with" : "without"));

    graphicsManager.initOpenGL();
    initArrays(graphicsManager.getMaxVertices());
    graphicsManager.updateTextureCompressionFormat();
    graphicsManager.updateTextureFormat();
    updateMemoryInfo();

    GLint texSize;
    bool rectTex = graphicsManager.supportExtension(
        "GL_ARB_texture_rectangle");
    if (rectTex
        && OpenGLImageHelper::getInternalTextureType() == 4
        && getOpenGL() != RENDER_GLES_OPENGL
        && getOpenGL() != RENDER_MODERN_OPENGL
        && config.getBoolValue("rectangulartextures")
        && !graphicsManager.isUseTextureSampler())
    {
        logger->log1("using GL_ARB_texture_rectangle");
        OpenGLImageHelper::mTextureType = GL_TEXTURE_RECTANGLE_ARB;
        glEnable(GL_TEXTURE_RECTANGLE_ARB);
        glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &texSize);
        OpenGLImageHelper::mTextureSize = texSize;
        logger->log("OpenGL texture size: %d pixels (rectangle textures)",
            OpenGLImageHelper::mTextureSize);
    }
    else
    {
        OpenGLImageHelper::mTextureType = GL_TEXTURE_2D;
        glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize);
        OpenGLImageHelper::mTextureSize = texSize;
        logger->log("OpenGL texture size: %d pixels",
            OpenGLImageHelper::mTextureSize);
    }
    return videoInfo();
#else  // USE_OPENGL

    return false;
#endif  // USE_OPENGL
}
int main(int argc, char* argv[])
{
	double starttime, finishtime, runtime;
	// i know it doesn't scale, but double pointers are ugly
	long *taskids[32];
	pthread_t threads[32];
	int rc;
	long t;
	float* tempPtr;
		
	starttime = When();
	
	numThreads = atoi(argv[1]);
	
	if (numThreads > 32)
	{
		printf("\nCurrent code won't scale above 32 threads.");
	}
	
	ptrFrom = &arrFrom[0];
	ptrTo = &arrTo[0];
	
	
	initArrays();
	steadyState = 0;
	
	pthread_mutex_init(&critical_steady, NULL);
	pthread_barrier_init(&barrier_first,NULL,numThreads+1);
	pthread_barrier_init(&barrier_second,NULL,numThreads+1);
	
	for(t=0; t<numThreads; t++)
	{
		taskids[t] = (long *) malloc(sizeof(long));
		*taskids[t] = t;
		//printf("Creating thread %ld\n", t+1);
		rc = pthread_create(&threads[t], NULL, iterOverMyRows, (void *) taskids[t]);
	}
	
	while (!steadyState)
	{
		steadyState = 1;
    
		
		pthread_barrier_wait(&barrier_first);
		
		
		pthread_barrier_wait(&barrier_second);
		
		iterCount++;
		tempPtr = ptrFrom;
		ptrFrom = ptrTo;
		ptrTo = tempPtr;


	}	
	
	// start global count
	cells50 = 0;
	
	pthread_mutex_init(&critical_count, NULL);
	
	for(t=0; t<numThreads; t++)
	{
		taskids[t] = (long *) malloc(sizeof(long));
		*taskids[t] = t+1;
		//printf("Creating thread %ld\n", t+1);
		rc = pthread_create(&threads[t], NULL, countCells50, (void *) taskids[t]);
	}

	for(t=0;t<numThreads;t++)
	{
		rc = pthread_join(threads[t],NULL);
	}
	
	
	finishtime = When();
	
	printf("\nNumber of iterations: %d", iterCount);
	printf("\nNumber of cells w/ temp greater than 50: %d", cells50);
	
	runtime = finishtime - starttime;
	
	printf("\nTime taken: %f\n", runtime);
	
	//pthread_exit(NULL);
}
예제 #20
0
void 
AttributeValues::registerAndInitArrays(AttribSet &attribs) {

	initArrays(attribs);
}
예제 #21
0
void Plume::setSettings(){
    deleteObjects();
    initArrays();
}
예제 #22
0
int main(int iArgCnt, char* sArrArgs[])
{
   int iIterationNo = 0;
   int iArrayIndex = 0;
   double dSubResult = 0, dTotalResult = 0;
   double dTime0 = 0, dTime1 = 0, dTimeDiff = 0, dMinTimeDiff = 1000, dMaxTimeDiff = 0;
   MPI_Status statusX, statusY;

   parseInputs(iArgCnt, sArrArgs);

   MPI_Init(&iArgCnt, &sArrArgs);
   MPI_Comm_size(MPI_COMM_WORLD, &GiProcessCnt);
   MPI_Comm_rank(MPI_COMM_WORLD, &GiProcessRank);

   initArrays();

   for(iIterationNo = 0; iIterationNo < GiIterationCnt; iIterationNo++)
   {
      dSubResult = 0;

      MPI_Barrier(MPI_COMM_WORLD);
      dTime0 = MPI_Wtime();
      if(GiProcessCnt > 1)
      {
         if(GiProcessRank == 0)
         {
            for(iArrayIndex = 1; iArrayIndex < GiProcessCnt; iArrayIndex++)
            {
               MPI_Send((GdArrX + (GiSubVectorLength * iArrayIndex)), GiSubVectorLength, MPI_DOUBLE, iArrayIndex, 0, MPI_COMM_WORLD);
               MPI_Send((GdArrY + (GiSubVectorLength * iArrayIndex)), GiSubVectorLength, MPI_DOUBLE, iArrayIndex, 0, MPI_COMM_WORLD);

               /*printf("Process0: Subarrays are sent to Process%d!\n", iArrayIndex);*/
            }

            for(iArrayIndex = 0; iArrayIndex < GiSubVectorLength; iArrayIndex++)
            {
               dSubResult += (GdArrX[iArrayIndex] * GdArrY[iArrayIndex]);
            }
            /*printf("Process0: I did my job and I will be waiting for the subresults!\n");*/
         }
         else
         {
            MPI_Recv(GdArrSubX, GiSubVectorLength, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &statusX);
            MPI_Recv(GdArrSubY, GiSubVectorLength, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &statusY);

            for(iArrayIndex = 0; iArrayIndex < GiSubVectorLength; iArrayIndex++)
            {
               dSubResult += (GdArrSubX[iArrayIndex] * GdArrSubY[iArrayIndex]);
            }

            /*printf("Process%d: I did my job and I will be sending my result to Process0!\n", GiProcessRank);*/
         }
      }
      else
      {
         for(iArrayIndex = 0; iArrayIndex < GiVectorLength; iArrayIndex++)
         {
            dSubResult += (GdArrX[iArrayIndex] * GdArrY[iArrayIndex]);
         }
      }

      MPI_Barrier(MPI_COMM_WORLD);
      MPI_Reduce(&dSubResult, &dTotalResult, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);

      dTime1 = MPI_Wtime();
      dTimeDiff = (dTime1 - dTime0);

      if(dTimeDiff > dMaxTimeDiff)
         dMaxTimeDiff = dTimeDiff;
      if(dTimeDiff < dMinTimeDiff)
         dMinTimeDiff = dTimeDiff;
   }

   if(GiProcessRank == 0)
      printf("Result=%f\nMin Time=%f uSec\nMax Time=%f uSec\n", dTotalResult, (1.e6 * dMinTimeDiff), (1.e6 * dMaxTimeDiff));
   
   MPI_Finalize();

   return 0;
}
예제 #23
0
RCArduinoReceiver::RCArduinoReceiver() {
  initArrays();
}