예제 #1
0
void initMandelbrot(int p, double a,double b,double c,double d,double s,char* f, int t) {
    //inicio del reloj
    clock_t start = clock();

    int* T = calcularMatriz(a,b,c,d,s);
    printf("[%d|%d]\n",T[0],T[1] );
    if(T[0]==T[1]) {
        float * M=matrixGen(T[0]);
        int i;
        pthread_t* thread = malloc(sizeof(pthread_t)*t);
        int filas_thread=T[0]/t;
        for (i = 0; i < t-1; ++i)
        {
            params* par = malloc(sizeof(params));
            par->M = M;
            par->size = T[0];
            par->a = a;
            par->b = b;
            par->m = s;
            par->depth=p;
            par->Yi=i*filas_thread;
            par->Yf=(i+1)*filas_thread-1;
            //thread     nose  función         parametros
            int resp = pthread_create(&thread[i], NULL,mandelbrot, (void*) par);
        }
        params* par = malloc(sizeof(params));
        par->M = M;
        par->size = T[0];
        par->a = a;
        par->b = b;
        par->m = s;
        par->depth=p;
        par->Yi=(t-1)*filas_thread;
        par->Yf=(t)*filas_thread+(T[0]%t)-1;//para que se incluyan las filas del resto
        int resp = pthread_create(&thread[t-1], NULL,mandelbrot, (void*) par);
        for (i = 0; i < t; ++i)
        {
            //se esperan a los thread para la generacion del archivo
            pthread_join(thread[i], NULL);
        }
        generaArchivo(M,f,T[0]);
        //destroy segment
        shmdt(M);
        shmctl(shmid,  IPC_RMID, NULL);
    }
    else {
        printf("la matriz debe ser cuadrada\n");
        exit(EXIT_FAILURE);
    }
    //impresion del tiempo
    printf("Tiempo transcurrido: %f\n", ((double)clock() - start) / CLOCKS_PER_SEC);

}
예제 #2
0
void initMandelbrot(int p, float a,float b,float c,float d,float s,char* f,int t){
    //inicio del reloj
    clock_t start = clock();
    int* T = calcularMatriz(a,b,c,d,s);
    printf("[%d|%d]\n",T[0],T[1] );
    if(T[0]==T[1]){ 
        float ** M=matrixGen(T[0]);
        int i;
        pthread_t* thread = malloc(sizeof(pthread_t)*t);
        int filas_thread=T[0]/t;
        gM=M;
        gSize= T[0];
        gA= a;
        gB = b;
        gm = s;
        gDepth = p;
        FT=filas_thread;
        int saisof=sizeof(int);
        for (i = 0; i < t-1; ++i)
        {
                                    // thread    return  función         parametros
            int resp = pthread_create(&thread[i], NULL,mandelbrot, NULL);
        }
        //para que se incluyan las filas del resto
        int resp = pthread_create(&thread[t-1], NULL,mandelbrot, NULL);
        for (i = 0; i < t; ++i)
        {
            //se esperan a los thread para la generacion del archivo
            pthread_join(thread[i], NULL);
        }

        generaArchivo(M,f,T[0]);
    }
    else{
        printf("la matriz debe ser cuadrada\n");
        exit(EXIT_FAILURE);
    }
    //impresion del tiempo
    printf("Tiempo transcurrido: %f\n", ((double)clock() - start) / CLOCKS_PER_SEC);
}
예제 #3
0
파일: main.c 프로젝트: clupin/Lab4Sistope
void initMandelbrot(int p, double a,double b,double c,double d,double s,char* f){
    //inicio del reloj
    clock_t start = clock();

    int* t = calcularMatriz(a,b,c,d,s);
    printf("[%d|%d]\n",t[0],t[1] );
    if(t[0]==t[1]){ 
        float * M=matrixGen(t[0]);
        mandelbrot(M,t[0],a , b, s, p);
        generaArchivo(M,f,t[0]);
        //destroy segment
        shmdt(M);
        shmctl(shmid,  IPC_RMID, NULL);
    }
    else{
        printf("la matriz debe ser cuadrada\n");
        exit(EXIT_FAILURE);
    }
    //impresion del tiempo
    printf("Tiempo transcurrido: %f\n", ((double)clock() - start) / CLOCKS_PER_SEC);

}
예제 #4
0
파일: helloDSP.c 프로젝트: Imara90/ESLab
// WARNING mxSize is the matrixSize here
NORMAL_API DSP_STATUS helloDSP_Execute(IN Uint32 mxSize, Uint8 processorId, Uint32* matrixA, Uint32* matrixB, Uint32* matrixC)
{
	DSP_STATUS status = DSP_SOK;
	Uint16 sequenceNumber = 0;
	Uint16 msgId = 0;
	Uint32 i, j;
	ControlMsg *msg;
	Uint8 flag = 0;

	Uint32 matrixD[mxSize * mxSize];

	Uint32 numElements, numMessages, elementCount, messageCount;
	Uint32 sizeElements, numProdMessages, matrixCount, prodElements;
	Char8 ascii_string[STRING_SIZE + 1];
	Char8 null_string[STRING_SIZE + 1] = {'\0','\0','\0','\0','\0','\0'};

	myStrcpy(ascii_string, null_string);

	SYSTEM_0Print("Entered helloDSP_Execute ()\n");

	// Wait for the first DSP is awake message
	status = MSGQ_get(SampleGppMsgq, WAIT_FOREVER, (MsgqMsg *) &msg);
	if (DSP_FAILED(status))
	{
		SYSTEM_1Print("MSGQ_get () failed. Status = [0x%x]\n", status);
	}

	// TODO possibly verify the data?

	SYSTEM_1Print("Received message: %s\n", (Uint32) msg->arg1);

	SYSTEM_0Print("Generated matrices:\n");
	// Generate the matrices after the DSPLink is established
	matrixGen(mxSize, matrixA, matrixB);

	// Have to translate the Int32 matrix elements to string elements
	// or the communication protocol
	prodElements = (mxSize * mxSize);
	numElements = (mxSize * mxSize * 2);
	sizeElements = numElements * STRING_SIZE;
	numMessages = ((sizeElements - 1) / ARG_MSG) + 1;
	numProdMessages = (((sizeElements / 2) - 1) / ARG_MSG) + 1;

	//SYSTEM_2Print("NumElements: %d, NumMessages: %d\n", numElements, numMessages);

	// WARNING Sending 5 Char8 each for loop
	// Start sending the matrices to the DSP which is not waiting
	for (messageCount = 0, elementCount = 0; messageCount < numMessages; messageCount++)
	{
		// First send a message, then receive
		//for ( ; (((elementCount - (messageCount * ARG_MSG)) * STRING_SIZE) < ARG_MSG ) && elementCount < numElements; elementCount++)

#if defined (PROFILE)
		SYSTEM_GetStartTimeDspEnc();
#endif
		for (; (elementCount - (messageCount * ARG_MSG)) < ARG_MSG && elementCount < numElements; elementCount++)
		{
			//SYSTEM_0Print("Putting element in a message\n");
			//itoa
			if(elementCount < prodElements)
			{
				SYSTEM_itoa(matrixA[elementCount], ascii_string, 10);
				//SYSTEM_1Print("Looping through string: %s in MatrixA\n", (Uint32) ascii_string);
			}
			else
			{
				SYSTEM_itoa(matrixB[elementCount - prodElements], ascii_string, 10);
				//SYSTEM_1Print("Looping through string: %s in MatrixB\n", (Uint32) ascii_string);
			}
			//SYSTEM_0Print("After SYSTEM_itoa\n");

			// loop through characters of the string
			for (i = 0; i < STRING_SIZE; i++)
			{
				msg->arg1[((elementCount * STRING_SIZE) - (messageCount * ARG_MSG)) + i] = ascii_string[i];
				//SYSTEM_sprintf(msg->arg1[(elementCount - (messageCount * ARG_MSG)) + i] = ascii_string[i];
			}
			// clean the string
			myStrcpy(ascii_string, null_string);
		}

#if defined (PROFILE)
		SYSTEM_GetEndTimeDspEnc();
#endif

		//SYSTEM_0Print("Filled a single message\n");

		// After filling a single message, should send it to the DSP and wait for a reply 
		// unless it is the last one
		if (DSP_SUCCEEDED(status))
		{
			//SYSTEM_0Print("DSP succeeded after filling\n");

#if defined (PROFILE)
			SYSTEM_GetStartTimeDspMes();
#endif
			msgId = MSGQ_getMsgId(msg);
			MSGQ_setMsgId(msg, msgId);
			// TODO set the command flag of the msg to distinguish
			status = MSGQ_put(SampleDspMsgq, (MsgqMsg) msg);
			if (DSP_FAILED(status))
			{
				MSGQ_free((MsgqMsg) msg);
				SYSTEM_1Print("MSGQ_put () failed. Status = [0x%x]\n", status);
			}
#if defined (PROFILE)
			else {
				SYSTEM_GetEndTimeDspMes();
				SYSTEM_GetStartTimeDspCalc();
			}
#endif
		}

		//SYSTEM_0Print("Message send\n");

		sequenceNumber++;
		// Make sure that the sequenceNumber stays within the permitted
		// range for applications. 
		if (sequenceNumber == MSGQ_INTERNALIDSSTART)
		{
			//SYSTEM_0Print("Something with sequences\n");
			sequenceNumber = 0;
		}
		// If it is the last message, don't wait for an acknowledge
		if (messageCount + 1 < numMessages)
		{
			// Wait for a response of the DSP before sending a reply
			status = MSGQ_get(SampleGppMsgq, WAIT_FOREVER, (MsgqMsg *) &msg);
			if (DSP_FAILED(status))
			{
				SYSTEM_1Print("MSGQ_get () failed. Status = [0x%x]\n", status);
			}

			//SYSTEM_1Print("Received: %s\n", (Uint32) msg->arg1);
		}
	}

	//SYSTEM_0Print("Sending completed..\n");

	// TODO start receiving the product matrix 
	// WARNING wait and acknowledge except for last loop
	for (messageCount = 0, elementCount = 0, matrixCount = 0; messageCount < numProdMessages; messageCount++)
	{
		status = MSGQ_get(SampleGppMsgq, WAIT_FOREVER, (MsgqMsg *) &msg);

		if (messageCount == 0) {
#if defined (PROFILE)
			SYSTEM_GetEndTimeDspCalc();
#endif
			SYSTEM_0Print("\nProduct matrix on DSP:\n");
		}
		//SYSTEM_1Print("Message received: %s\n", (Uint32) msg->arg1);
		if (DSP_FAILED(status))
		{
			SYSTEM_1Print("MSGQ_get () failed. Status = [0x%x]\n", status);
		}
		// Put the received message in the matrixC
		for (; matrixCount < prodElements && (elementCount - (messageCount * ARG_MSG)) < ARG_MSG && elementCount < (prodElements * STRING_SIZE); matrixCount++, elementCount += STRING_SIZE)
		{
			// atoi
			for (i = 0; i < STRING_SIZE; i++)
			{
				ascii_string[i] = msg->arg1[elementCount + i];
			}
			ascii_string[5] = '\0';
			/*
			 if (matrixCount >= 72)
			 {
			 SYSTEM_1Print("Ascii string received: %s\n", ascii_string);
			 }
			 */
			// Put it in the matrixC
			matrixC[matrixCount] = atoi(ascii_string);
			// print the string
			if (matrixCount % mxSize == 0)
			{
				SYSTEM_0Print("\n");
			}
			SYSTEM_1Print("%d ", matrixC[matrixCount]);

			// Clean the string
			myStrcpy(ascii_string, null_string);
		}

		// If this is not the last message, send an acknowledge
		if (messageCount + 1 < numProdMessages)
		{
			// Send the same message received in earlier MSGQ_get () call. 
			if (DSP_SUCCEEDED(status))
			{
				msgId = MSGQ_getMsgId(msg);
				MSGQ_setMsgId(msg, msgId);
				status = MSGQ_put(SampleDspMsgq, (MsgqMsg) msg);
				if (DSP_FAILED(status))
				{
					MSGQ_free((MsgqMsg) msg);
					SYSTEM_1Print("MSGQ_put () failed. Status = [0x%x]\n", status);
				}
			}

			sequenceNumber++;
			// Make sure that the sequenceNumber stays within the permitted
			// range for applications. 
			if (sequenceNumber == MSGQ_INTERNALIDSSTART)
			{
				sequenceNumber = 0;
			}
		}
	}

	SYSTEM_0Print("\n");

	MSGQ_free((MsgqMsg) msg);
	//SYSTEM_0Print("After freeing the message..\n");

	SYSTEM_0Print("\nProduct matrix on GPP:\n");

#if defined (PROFILE)
	SYSTEM_GetStartTimeGpp();
#endif

	matMult(matrixA, matrixB, matrixD, mxSize);

#if defined (PROFILE)
	SYSTEM_GetEndTimeGpp();
#endif

	// compare the matrices
	for(i=0; i<mxSize; i++)
	{
		for(j=0; j<mxSize; j++)
		{
			if(matrixC[i * mxSize + j] != matrixD[i * mxSize + j])
			{
				SYSTEM_2Print("Matrices are not equal row: %d, column: %d\n", i, j);
				flag = 1;
				break;
			}
		}
	}
	if (flag == 0)
	{
		SYSTEM_0Print("\nMatrix products are equal\n");
	}

	SYSTEM_0Print("Leaving helloDSP_Execute ()\n");

#if defined (PROFILE)
	if (DSP_SUCCEEDED(status))
	{
		SYSTEM_GetProfileInfoGpp();
		SYSTEM_GetProfileInfoDsp(numMessages); //is numProdMessages interesting?
	}
#endif

	return status;
}