Foros del Web » Programación para mayores de 30 ;) » C/C++ »

sugerencia sobre implementacion

Estas en el tema de sugerencia sobre implementacion en el foro de C/C++ en Foros del Web. QUE TAL A TODOS OCUPO UN POCO DE SU AYUDA, QUIERO IMPLEMENTARLE A LA FUNCION MERCATOR, SEMAFOROS O MENSAJES PERO OCUPO SABER CUAL ES EL ...
  #1 (permalink)  
Antiguo 26/10/2009, 08:40
 
Fecha de Ingreso: marzo-2009
Mensajes: 163
Antigüedad: 15 años, 1 mes
Puntos: 0
sugerencia sobre implementacion

QUE TAL A TODOS OCUPO UN POCO DE SU AYUDA, QUIERO IMPLEMENTARLE A LA FUNCION MERCATOR, SEMAFOROS O MENSAJES PERO OCUPO SABER CUAL ES EL MAS OPTIMO PARA ESTA FUNCION, ALGUIEN PUEDE AYUDARME CON SUGERENCIAS O EXPLICANDOME CUAL ES MEJOR QUE CUAL? LES PONGO EL CODIGO DE LA FUNCION

Código:
/*
	This simple code demonstrates CreateEvent, WaitForMultipleObjects 
	Win32 API functions and event objects.

	This code computes sum of Mercator's series.

	Mercator's series expression for ln( x + 1 ) function is:
 
		ln( x + 1 ) = x - x^2/2 + x^3/3 - x^4/4 + x^5/5 - ...

		for -1 < x <= 1.
*/

#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <windows.h>
#include <math.h>


#define NUMTHREADS 4
#define SERIES_MEMBER_COUNT 20000

HANDLE *threadHandles, masterThreadHandle;
CRITICAL_SECTION countCS;
double *sums;
double x = 1.0, res = 0.0;
int threadCount = 0;

double getMember(int n, double x)
{
	double numerator = 1;
	for( int i=0; i<n; i++ )
		numerator = numerator*x;

	if ( n % 2 == 0 )
		return ( - numerator / n );
	else
		return numerator/n;
}

DWORD WINAPI threadProc(LPVOID par)
{
	int threadIndex = *((int *)par);
	sums[threadIndex] = 0;
	for(int i=threadIndex; i<SERIES_MEMBER_COUNT;i+=NUMTHREADS)
		sums[threadIndex] += getMember(i+1, x);

	//Signal Master thread that one more processing thread is done
	EnterCriticalSection(&countCS);
	  threadCount++;
    LeaveCriticalSection(&countCS);

	delete par;
	return 0;
}

DWORD WINAPI masterThreadProc(LPVOID par)
{
	for( int i=0; i<NUMTHREADS; i++ ) ResumeThread(threadHandles[i]);  // Start computing threads

	while (threadCount != NUMTHREADS) {}   // busy wait until all threads are done with computation of partial sums
	res = 0;
	for(int i=0; i<NUMTHREADS; i++)
		res += sums[i];
	return 0;
}

int main()
{
	threadHandles = new HANDLE[NUMTHREADS + 1];
	InitializeCriticalSection(&countCS);
	sums = new double[NUMTHREADS];
	clock_t start,stop;

	start=clock();
	for(int i=0; i<NUMTHREADS;i++)
	{
		int * threadIdPtr = new int;
		*threadIdPtr = i;
		threadHandles[i] = CreateThread(NULL, 0, threadProc, threadIdPtr, CREATE_SUSPENDED, NULL);
	}
	threadHandles[NUMTHREADS] = CreateThread(NULL, 0, masterThreadProc, NULL, 0, NULL);
	
	printf("Count of ln(1 + x) Mercator's series members is %d\n",SERIES_MEMBER_COUNT);
	printf("Argument value of x is %f\n", (double)x);

	WaitForMultipleObjects(NUMTHREADS+1,threadHandles,TRUE,INFINITE);
	stop=clock();

	printf("Tiempo = %2.7f\n",(float)(stop - start)/ CLOCKS_PER_SEC);

	for(int i=0; i<NUMTHREADS+1; i++ ) CloseHandle(threadHandles[i]);

	delete threadHandles;
	DeleteCriticalSection(&countCS);
	delete sums;

	printf("Result is %10.8f\n", res);
	printf("By function call ln(1 + %f) = %10.8f\n",x, log(1+x));
	printf("Press any key ... ");
	getch();
	return 0;
}
  #2 (permalink)  
Antiguo 26/10/2009, 18:46
 
Fecha de Ingreso: octubre-2009
Mensajes: 1
Antigüedad: 14 años, 6 meses
Puntos: 0
Respuesta: sugerencia sobre implementacion

ESO ME SONO A QUE HAGAMOS TU TAREA
HAY VARIAS PAGINAS EN DONDE PUEDES ENCONTRAR INFORMACION. TE SUGIERO EMPEZAR CON UN BUSCADOR (GOOGLE) = )

HECHALE GANAS AMIGO PERO PARA CUALQUIER DUDA MAS PEQUEÑA Y CONCRETA ESTAMOS A TU SERVICIO.


PD: UN LIBRO MUY BUENO QUE ALGUNOS DE MIS COLEGAS RECOMIENDAN ES EL DE
"SISTEMAS OPERATIVOS DE STALLINGS", O SIMILAR, NO RECUERDO BIEN EL NOMBRE; PERO TIENE ALGUNOS DINOSAURIOS DE PORTADA =)

PD2: SALUDOS POR PARTE DE TODO EL STAFF DE OPERATIVOS.
  #3 (permalink)  
Antiguo 26/10/2009, 19:49
 
Fecha de Ingreso: marzo-2009
Mensajes: 163
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: sugerencia sobre implementacion

no es tarea, sino ocupo varias observaciones porque tengo que hacer un debate y ocupo ayuda de expertos para fundamentar bien que es mejor que el otro
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:06.