#include <v_lib.h>

void somelongop()
{
	/*
	 * Solution of linear system of order 2000
	 */
#define	N 2000
	int i;
	matrix_p a;
	vector_p b, x;
	a = matAlloc(N,N);
	b = vecAlloc(N);
	matUnit(a);
	for(i=0;i<N;++i)
		b->elements[i] = i;
	x = matSolve(a,b,false);
	memFree(x);
}

volatile int spinlock = 1;

void V_CALL th(void *arg)
{
	while(spinlock);
	somelongop();
}

int main(int argc,char *argv[])
{
	vhandle_t t1, t2;
	unsigned ms;
	logStartConsoleLog();
	logUpperLevel(LOG_TRACE);
	ms = timeTickCount();
	puts("begins sequential execution");
	somelongop();
	somelongop();
	ms = timeTickCount() - ms;
	printf("Sequential exec: %u ms\n",ms);
	t1 = threadCreate(th,NULL);
	t2 = threadCreate(th,NULL);
	ms = timeTickCount();
	spinlock = 0;
	threadJoin(t1,NULL);
	threadJoin(t2,NULL);
	ms = timeTickCount() - ms;
	printf("Parallel exec: %u ms\n",ms);
	memPrintStats();
	return 0;
}
