Ejemplo n.º 1
0
void getDoneRowInfoNew(ParallelETree *tree,const int *postorder,const int *postorder_inv,const int treeInternalSize)
{	
	int i;

	int *priorityTable = getMempoolSet(sizeof(int)*(treeInternalSize+1));
	for(i=0;i<treeInternalSize+1;i++) priorityTable[i] = treeInternalSize - postorder_inv[i];

	gdsl_queue_t freeSinkList = gdsl_queue_alloc("freeSinkListTemp",alloc_int,free_int);
	getInitSinkList(freeSinkList,tree);
	// set the doneRow information
	while(gdsl_queue_get_size(freeSinkList)!=0)
	{
		int *indexInQueue = gdsl_queue_get_head(freeSinkList);
		gdsl_queue_remove(freeSinkList);
		updateFreeSinkList(freeSinkList,tree,*indexInQueue,treeInternalSize,priorityTable);
		retMempoolSet(indexInQueue,sizeof(int));
	}

	// recover the setting of visiting the tree
	for(i=0;i<tree->size;i++)
	{
		if(tree->node[i] == NULL) continue;
		else tree->node[i]->visitLog = notvisit;
	}

	gdsl_queue_free(freeSinkList);
	retMempoolSet(priorityTable,sizeof(int)*(treeInternalSize+1));
}
Ejemplo n.º 2
0
SparseNetlistQuad *parseSparseQuadInput(SparseNetlistQuad *ptr, const char *filename)
{

	FILE *fp = fopen(filename,"r");
	char line[1024];
	char *status;
	int i,j,k;
	//==========================================================
	
	ptr->a = createSparseQuadMatrix(ptr->nodeNum,ptr->nodeNum,ptr->gvNum);
	ptr->b = createSparseQuadMatrix(ptr->nodeNum,ptr->nodeNum,ptr->gvNum);
	ptr->c = createSparseQuadMatrix(ptr->nodeNum,ptr->nodeNum,ptr->gvNum);
	ptr->u = createQuadMatrix(ptr->nodeNum,ptr->stepNum,ptr->gvNum);
	ptr->gVarientTable = createSparseGVarientTable(ptr->nodeNum,ptr->nodeNum);	
	
	gdsl_queue_t voltageInNode = gdsl_queue_alloc("voltageInNode",allocInt,freeInt);
	double maxG = 10;

	LinearNodeList *linearNodeList = createLinearNodeList();
	ptr->nonlinearNodeList = createNonlinearNodeList();

	while( (status=fgetl(line,1024,fp))!=NULL )
	{
		if(line[0] == 'G' || line[0] == 'g')
		{
			CircuitEntryQuad *circuit = createCircuitEntryQuad();
			setCircuitEntryQuad(circuit,line);
	
			QuadElement *tempQuadElement = createQuadElement(ptr->gvNum);
			const QuadElement *quadElementInList = getLinearNodeList(linearNodeList,circuit->val,circuit->alphaName,circuit->betaName,circuit->gammaName);
			if(quadElementInList == NULL)
			{
				tempQuadElement->m = circuit->val;
				tempQuadElement->alpha = getAlpha(circuit->alphaName);
			
				gsl_matrix *betaFromDlmread = gsl_matrix_alloc(ptr->gvNum,1);
				dlmread(betaFromDlmread,circuit->betaName," ",0,0,ptr->gvNum-1,0);
				gsl_matrix_to_double(tempQuadElement->beta,betaFromDlmread);
				gsl_matrix_free(betaFromDlmread);
			
				gsl_matrix *gammaFromDlmread = gsl_matrix_alloc(ptr->gvNum,ptr->gvNum);
				dlmread(gammaFromDlmread,circuit->gammaName," ",0,0,ptr->gvNum-1,ptr->gvNum-1);
				gsl_matrix_to_double(tempQuadElement->gamma,gammaFromDlmread);
				gsl_matrix_free(gammaFromDlmread);

				insertLinearNodeList(linearNodeList,circuit->val,circuit->alphaName,circuit->betaName,circuit->gammaName,tempQuadElement);
			}
			else
			{
				copyQuadElement(tempQuadElement,quadElementInList);
			}
			const int pos = toZeroBase(circuit->pos);
			const int neg = toZeroBase(circuit->neg);
			if(pos != -1)
			{
				decSparseQuadMatrix(ptr->a,tempQuadElement,pos,pos);
			}
			if(neg != -1)
			{
				decSparseQuadMatrix(ptr->a,tempQuadElement,neg,neg);
			}
			if(pos!=-1 && neg!=-1)
			{
				incSparseQuadMatrix(ptr->a,tempQuadElement,neg,pos);
				incSparseQuadMatrix(ptr->a,tempQuadElement,pos,neg);
			}
			
			if(abs(circuit->val) > maxG )	maxG = abs(circuit->val);
			freeCircuitEntryQuad(circuit);
			freeQuadElement(tempQuadElement);
		}		
		else if(line[0] == 'C' || line[0] == 'c')
		{
			CircuitEntryQuad *circuit = createCircuitEntryQuad();
			setCircuitEntryQuad(circuit,line);
			
			QuadElement *tempQuadElement = createQuadElement(ptr->gvNum);
			const QuadElement *quadElementInList = getLinearNodeList(linearNodeList,circuit->val,circuit->alphaName,circuit->betaName,circuit->gammaName);
			if(quadElementInList == NULL)
			{
				tempQuadElement->m = circuit->val;
				tempQuadElement->alpha = getAlpha(circuit->alphaName);
			
				gsl_matrix *betaFromDlmread = gsl_matrix_alloc(ptr->gvNum,1);
				dlmread(betaFromDlmread,circuit->betaName," ",0,0,ptr->gvNum-1,0);
				gsl_matrix_to_double(tempQuadElement->beta,betaFromDlmread);
				gsl_matrix_free(betaFromDlmread);
			
				gsl_matrix *gammaFromDlmread = gsl_matrix_alloc(ptr->gvNum,ptr->gvNum);
				dlmread(gammaFromDlmread,circuit->gammaName," ",0,0,ptr->gvNum-1,ptr->gvNum-1);
				gsl_matrix_to_double(tempQuadElement->gamma,gammaFromDlmread);
				gsl_matrix_free(gammaFromDlmread);

				insertLinearNodeList(linearNodeList,circuit->val,circuit->alphaName,circuit->betaName,circuit->gammaName,tempQuadElement);
			}
			else
			{
				copyQuadElement(tempQuadElement,quadElementInList);
			}
			const int pos = toZeroBase(circuit->pos);
			const int neg = toZeroBase(circuit->neg);
			if(pos != -1)
			{
				incSparseQuadMatrix(ptr->c,tempQuadElement,pos,pos);
			}
			if(neg != -1)
			{
				incSparseQuadMatrix(ptr->c,tempQuadElement,neg,neg);
			}
			if(pos!=-1 && neg!=-1)
			{
				decSparseQuadMatrix(ptr->c,tempQuadElement,pos,neg);
				decSparseQuadMatrix(ptr->c,tempQuadElement,neg,pos);
			}
			freeCircuitEntryQuad(circuit);
			freeQuadElement(tempQuadElement);
		}
		else if(line[0] =='V' || line[0] =='v')
		{
			CircuitEntryQuad *circuit = createCircuitEntryQuad();
			setVoltageIn(circuit,line);
			gsl_matrix *tempM = gsl_matrix_calloc(1,ptr->stepNum);
			gsl_matrix *tempAlpha = gsl_matrix_calloc(1,ptr->stepNum);
			gsl_matrix *tempBeta = gsl_matrix_calloc(ptr->gvNum,ptr->stepNum);
			gsl_matrix *tempGamma = gsl_matrix_calloc(ptr->gvNum*ptr->gvNum,ptr->stepNum);
			dlmread(tempM,circuit->mName,",",0,0,0,ptr->stepNum-1);
			dlmread(tempAlpha,circuit->alphaName,",",0,0,0,ptr->stepNum-1);
			dlmread(tempBeta,circuit->betaName,",",0,0,ptr->gvNum-1,ptr->stepNum-1);
			dlmread(tempGamma,circuit->gammaName,",",0,0,ptr->gvNum*ptr->gvNum-1,ptr->stepNum-1);	
			const int pos = toZeroBase(circuit->pos);
			const int neg = toZeroBase(circuit->neg);
			if(neg == -1)
			{
				// save the pos to the voltageInNode ~ used in pass 2 , to setup B
				gdsl_queue_insert(voltageInNode,&(circuit->pos));
				// for each step, set m, alpha, beta, and gamma
				for(i=0;i<ptr->stepNum;i++)
				{
					QuadElement *tempVin = createQuadElement(ptr->gvNum);
					gsl_matrix *betaVin = gsl_matrix_calloc(ptr->gvNum,1);
					gsl_matrix *gammaVin = gsl_matrix_calloc(ptr->gvNum,ptr->gvNum);
					// set beta
					for(j=0;j<ptr->gvNum;j++)
					{
						const double temp = gsl_matrix_get(tempBeta,j,i);
						gsl_matrix_set(betaVin,j,0,temp);
					}
					// set gamma
					for(j=0;j<ptr->gvNum;j++)
					{
						for(k=0;k<ptr->gvNum;k++)
						{
							const double temp = gsl_matrix_get(tempGamma,j*ptr->gvNum+k,i);
							gsl_matrix_set(gammaVin,j,k,temp);
						}
					}
					double *betaVinDouble = getMempoolSet(sizeof(double)*ptr->gvNum);
					double *gammaVinDouble = getMempoolSet(sizeof(double)*ptr->gvNum*ptr->gvNum);
					gsl_matrix_to_double(betaVinDouble,betaVin);
					gsl_matrix_to_double(gammaVinDouble,gammaVin);
					setQuadElement(tempVin,gsl_matrix_get(tempM,0,i),gsl_matrix_get(tempAlpha,0,i),betaVinDouble,gammaVinDouble);
					setQuadMatrix(ptr->u,tempVin,pos,i);
					freeQuadElement(tempVin);
					gsl_matrix_free(betaVin);
					gsl_matrix_free(gammaVin);
					retMempoolSet(betaVinDouble,sizeof(double)*ptr->gvNum);
					retMempoolSet(gammaVinDouble,sizeof(double)*ptr->gvNum*ptr->gvNum);
				}
			}
			else
			{
				fprintf(stderr,"voltage source does not connect to gnd\n");
			}
			gsl_matrix_free(tempM);
			gsl_matrix_free(tempAlpha);
			gsl_matrix_free(tempBeta);
			gsl_matrix_free(tempGamma);
			freeCircuitEntryQuad(circuit);
		}
		else if(line[0] == 'M' || line[0] =='m')
		{
			// ========================================================

			MosName *mosName = createMosName();
			setMosName(mosName,line);
			const NonlinearInfo *nonlinearNodeInList = getNonlinearNodeList(ptr->nonlinearNodeList,mosName->mName,mosName->alphaName,mosName->betaName,mosName->gammaName,mosName->configName);
			const NonlinearInfo *data = NULL;

			if(nonlinearNodeInList == NULL)
			{
				MosInfo *mosInfo = createAndSetMosInfo(mosName,ptr->gvNum);
				NonlinearInfo *input = createNonlinearInfo(mosInfo->vdsListSize,mosInfo->vgsListSize,mosInfo->vdsList,mosInfo->vgsList,mosInfo->ivTable,mosInfo->cgs,mosInfo->cgd);
				insertNonlinearNodeList(ptr->nonlinearNodeList,mosName->mName,mosName->alphaName,mosName->betaName,mosName->gammaName,mosName->configName,input);
				freeMosInfo(mosInfo);
				freeNonlinearInfo(input);
				data  = getNonlinearNodeList(ptr->nonlinearNodeList,mosName->mName,mosName->alphaName,mosName->betaName,mosName->gammaName,mosName->configName);
			}
			else
			{
				data = nonlinearNodeInList;
			}
			GControlInfo *newGControlInfo = createGControlInfo(data->vdsListSize,data->vgsListSize,ptr->gvNum);
			newGControlInfo->gate = mosName->gate;
			newGControlInfo->drain = mosName->drain;
			newGControlInfo->source = mosName->source;
			newGControlInfo->vdsList = data->vdsList;
			newGControlInfo->vgsList = data->vgsList;
			freeMosName(mosName);

			const int drain = toZeroBase(newGControlInfo->drain);
			const int gate = toZeroBase(newGControlInfo->gate);
			const int source = toZeroBase(newGControlInfo->source);
			
			newGControlInfo->type = gm;
			newGControlInfo->partialIdsVxs = data->partialIdsVgs;
			if(drain!=-1 && gate!=-1)
			{
				newGControlInfo->sign = -1;
				insertSparseGVarientTable(ptr->gVarientTable,newGControlInfo,drain,gate);
			}
			if(source!=-1)
			{
				newGControlInfo->sign = -1;
				insertSparseGVarientTable(ptr->gVarientTable,newGControlInfo,source,source);	
			}
			if(drain!=-1 && source!=-1)
			{
				newGControlInfo->sign = 1;
				insertSparseGVarientTable(ptr->gVarientTable,newGControlInfo,drain,source);	
			}
			if(gate!=-1 && source!=-1)
			{
				newGControlInfo->sign = 1;
				insertSparseGVarientTable(ptr->gVarientTable,newGControlInfo,gate,source);	
			}
			

			newGControlInfo->type = ro_1;
			newGControlInfo->partialIdsVxs = data->partialIdsVds;
			if(drain!=-1)
			{
				newGControlInfo->sign = -1;
				insertSparseGVarientTable(ptr->gVarientTable,newGControlInfo,drain,drain);	
			}
			if(source!=-1)
			{
				newGControlInfo->sign = -1;
				insertSparseGVarientTable(ptr->gVarientTable,newGControlInfo,source,source);	
			}
			if(drain!=-1 && source!=-1)
			{
				newGControlInfo->sign = 1;
				insertSparseGVarientTable(ptr->gVarientTable,newGControlInfo,drain,source);	
				insertSparseGVarientTable(ptr->gVarientTable,newGControlInfo,source,drain);	
			}
			freeGControlInfo(newGControlInfo);

			// ===== cgd =====
			QuadElement *cgd = createQuadElement(ptr->gvNum);
			copyQuadElement(cgd,data->cgd);
			if(gate!=-1 && drain!=-1)
			{
				decSparseQuadMatrix(ptr->c,cgd,gate,drain);
				decSparseQuadMatrix(ptr->c,cgd,drain,gate);
			}
			if(gate!=-1)
			{
				incSparseQuadMatrix(ptr->c,cgd,gate,gate);
			}
			if(drain!=-1)
			{
				incSparseQuadMatrix(ptr->c,cgd,drain,drain);
			}
			freeQuadElement(cgd);
			// ===== cgs =====
			QuadElement *cgs = createQuadElement(ptr->gvNum);
			copyQuadElement(cgs,data->cgs);
			if(gate!=-1 && source!=-1)
			{
				decSparseQuadMatrix(ptr->c,cgs,gate,source);
				decSparseQuadMatrix(ptr->c,cgs,source,gate);
			}
			if(gate!=-1)
			{
				incSparseQuadMatrix(ptr->c,cgs,gate,gate);
			}
			if(source!=-1)
			{
				incSparseQuadMatrix(ptr->c,cgs,source,source);
			}
			freeQuadElement(cgs);
		}
		else
		{
//			fprintf(stderr,"%s",line);
//			fprintf(stderr,"not defined yet\n");
		}
	}
	// the while loop of the first pass 
	fclose(fp);
//	dumpLinearNodeList(stdout,linearNodeList);
	freeLinearNodeList(linearNodeList);

	// pass 2 , to setup B and the diagonal of A
	QuadElement *maxGQuad = createQuadElement(ptr->gvNum);
	addConstantQuadElement(maxGQuad,maxG,maxGQuad);
	scaleQuadElement(maxGQuad,100,maxGQuad);
	while(!gdsl_queue_is_empty(voltageInNode))
	{
		int *ret = gdsl_queue_remove(voltageInNode);
		const int posNodeIndex = toZeroBase(*ret);
		// set A
		decSparseQuadMatrix(ptr->a,maxGQuad,posNodeIndex,posNodeIndex);
		// set B
		incSparseQuadMatrix(ptr->b,maxGQuad,posNodeIndex,posNodeIndex);
	}
	freeQuadElement(maxGQuad);
	gdsl_queue_free(voltageInNode);

	return ptr;
}
Ejemplo n.º 3
0
int main (void)
{
    int choice = 0;
    gdsl_queue_t q = gdsl_queue_alloc ("Q", alloc_integer, free_integer);
  
    do
	{
	    printf ("\t\tMENU - QUEUE\n\n");
	    printf ("\t1> Put\n");
	    printf ("\t2> Pop\n");
	    printf ("\t3> Get Head\n");
	    printf ("\t4> Get Tail\n");
	    printf ("\t5> Flush\n");
	    printf ("\t6> Search\n");
	    printf ("\t7> Display\n");
	    printf ("\t8> Dump\n");
	    printf ("\t9> XML display\n");
	    printf ("\t0> Quit\n\n" );
	    printf ("\t\tYour choice: " );
	    scanf ("%d", &choice );

	    switch (choice)
		{
		case 1:
		    {
			int value;
			printf ("Enter an integer value: ");
			scanf ("%d", &value);
			gdsl_queue_insert (q, (void*) &value);
		    }
		    break;

		case 2:
		    if (!gdsl_queue_is_empty (q))
			{
			    int* value = (int*) gdsl_queue_remove (q);
			    printf ("Value: %d\n", *value);
			    free_integer (value);
			}
		    else
			{
			    printf ("The queue '%s' is empty\n", gdsl_queue_get_name (q));
			}
		    break;
	  
		case 3:
		    {
			if (!gdsl_queue_is_empty (q)) 
			    {
				int head = *(int*) gdsl_queue_get_head (q);
				printf ("Head = %d\n", head);
			    }
			else
			    {
				printf ("The queue '%s' is empty\n", gdsl_queue_get_name (q));
			    }
		    }
		    break;

		case 4:
		    {
			if (!gdsl_queue_is_empty (q)) 
			    {
				int tail = *(int*) gdsl_queue_get_tail (q);
				printf ("Tail = %d\n", tail);
			    }
			else
			    {
				printf ("The queue '%s' is empty\n", gdsl_queue_get_name (q));
			    }
		    }
		    break;

		case 5:
		    if (gdsl_queue_is_empty (q))
			{
			    printf ("The queue '%s' is empty\n", gdsl_queue_get_name (q));
			}
		    else
			{
			    gdsl_queue_flush (q);
			}
		    break;

		case 6:
		    {
			int pos;
			int* value;
			printf ("Enter an integer value to search an element by its position: ");
			scanf ("%d", &pos);

			value = (int*) gdsl_queue_search_by_position (q, pos);
			if (value != NULL)
			    {
				printf ("Value found at position %d = %d\n", pos, *value);
			    }
		    }
		    break;

		case 7:
		    if (gdsl_queue_is_empty (q))
			{
			    printf ("The queue '%s' is empty\n", gdsl_queue_get_name (q));
			}
		    else
			{
			    printf ("%s = ", gdsl_queue_get_name (q));
			    gdsl_queue_map_forward (q, my_display_integer, NULL);
			}
		    break;

		case 8:
		    gdsl_queue_dump (q, my_write_integer, stdout, NULL);
		    break;

		case 9:
		    gdsl_queue_write_xml (q, my_write_integer, stdout, NULL);
		    break;
		}
	} 
    while (choice != 0);

    gdsl_queue_free (q);

    exit (EXIT_SUCCESS);
}
Ejemplo n.º 4
0
static void updateFreeSinkList(gdsl_queue_t freeSinkList, ParallelETree *tree, const int currentNodeIndex,const int treeInternalSize,const int *priorityTable)
{
	int rootIndex = currentNodeIndex/2;
	const int leftIndex = rootIndex*2;
	const int rightIndex = rootIndex*2 + 1;
	int *mark = getMempoolSet(sizeof(int)*(treeInternalSize+1));
	memset(mark,0,sizeof(int)*(treeInternalSize+1));

	tree->node[currentNodeIndex]->visitLog = visit;

	if(tree->node[rootIndex]==NULL)
	{
		retMempoolSet(mark,sizeof(int)*(treeInternalSize+1));
		return;
	}


	// reorder the queue .... suck implement
	if( tree->node[leftIndex]->visitLog==visit && tree->node[rightIndex]->visitLog==visit )
	{
		int i,j;
		int nnz = 0;
		while(gdsl_queue_get_size(freeSinkList)!=0)
		{
			int *indexInQueue = gdsl_queue_get_head(freeSinkList);
			gdsl_queue_remove(freeSinkList);
			mark[*indexInQueue] = 1;
			nnz++;
			retMempoolSet(indexInQueue,sizeof(int));
		}
		mark[rootIndex] = 1;
		nnz++;
		for(i=0;i<nnz;i++)
		{
			int maxIndex = -1;
			int maxPri = -1;
			for(j=1;j<treeInternalSize+1;j++)
			{
				if( (mark[j]==1) && (priorityTable[j] > maxPri))
				{
					maxPri = priorityTable[j];
					maxIndex = j;
				}
			}
			mark[maxIndex] = 0;
			gdsl_queue_insert(freeSinkList,&maxIndex);
		}
	}


	if( tree->node[leftIndex]->visitLog==visit && tree->node[rightIndex]->visitLog==visit )
	{
		int temp1,temp2;
		temp1 = GSL_MIN(tree->node[leftIndex]->doneRowBegin,tree->node[rightIndex]->doneRowBegin);
		temp2 = GSL_MIN(tree->node[leftIndex]->rowBegin,tree->node[rightIndex]->rowBegin);
//
		tree->node[rootIndex]->doneRowBegin = GSL_MIN(temp1,temp2);
		temp1 = GSL_MAX(tree->node[leftIndex]->doneRowEnd,tree->node[rightIndex]->doneRowEnd);
		temp2 = GSL_MAX(tree->node[leftIndex]->rowEnd,tree->node[rightIndex]->rowEnd);
		tree->node[rootIndex]->doneRowEnd = GSL_MAX(temp1,temp2);

	}
	
	retMempoolSet(mark,sizeof(int)*(treeInternalSize+1));
}