Index: /proiecte/Parallel-DT/R8/Src/discr.c
===================================================================
--- /proiecte/Parallel-DT/R8/Src/discr.c	(revision 67)
+++ /proiecte/Parallel-DT/R8/Src/discr.c	(revision 68)
@@ -6,8 +6,6 @@
 /*************************************************************************/
 
-
 #include "buildex.i"
 
-
 /*************************************************************************/
 /*									 */
@@ -16,44 +14,71 @@
 /*************************************************************************/
 
-
-    EvalDiscreteAtt(Att, Fp, Lp, Items)
-/*  ---------------  */ 
-    Attribute Att;
-    ItemNo Fp, Lp; 
-    ItemCount Items;
-{ 
-    ItemCount KnownItems;
-    float DiscrKnownBaseInfo(), ComputeGain(), TotalInfo();
-
-    ComputeFrequencies(Att, Fp, Lp);
-
-    KnownItems = Items - ValFreq[0];
-
-    /*  Special case when no known values of the attribute  */
-
-    if ( Items <= ValFreq[0] )
-    {
-	Verbosity(2) printf("\tAtt %s: no known values\n", AttName[Att]);
-
-	Gain[Att] = -Epsilon;
-	Info[Att] = 0.0;
-	return;
-    }
-
-    Gain[Att] = ComputeGain(DiscrKnownBaseInfo(KnownItems, MaxAttVal[Att]),
-			    UnknownRate[Att], MaxAttVal[Att], KnownItems);
-    Info[Att] = TotalInfo(ValFreq, 0, MaxAttVal[Att]) / Items;
-
-    Verbosity(2)
-    {
-    	printf("\tAtt %s", AttName[Att]);
-    	Verbosity(3) PrintDistribution(Att, MaxAttVal[Att], true);
-    	printf("\tinf %.3f, gain %.3f\n", Info[Att], Gain[Att]);
-    }
-
-} 
-
-
-
+EvalDiscreteAtt(Att, Fp, Lp, Items)
+	/*  ---------------  */
+	Attribute Att;ItemNo Fp, Lp;ItemCount Items; {
+	ItemCount KnownItems;
+	float DiscrKnownBaseInfo(), ComputeGain(), TotalInfo();
+
+	ComputeFrequencies(Att, Fp, Lp);
+
+	KnownItems = Items - ValFreq[0];
+
+	/*  Special case when no known values of the attribute  */
+
+	if (Items <= ValFreq[0]) {
+		Verbosity(2)
+			printf("\tAtt %s: no known values\n", AttName[Att]);
+
+		Gain[Att] = -Epsilon;
+		Info[Att] = 0.0;
+		return;
+	}
+
+	Gain[Att] = ComputeGain(DiscrKnownBaseInfo(KnownItems, MaxAttVal[Att]),
+			UnknownRate[Att], MaxAttVal[Att], KnownItems);
+	Info[Att] = TotalInfo(ValFreq, 0, MaxAttVal[Att]) / Items;
+
+	Verbosity(2) {
+		printf("\tAtt %s", AttName[Att]);
+		Verbosity(3)
+			PrintDistribution(Att, MaxAttVal[Att], true);
+		printf("\tinf %.3f, gain %.3f\n", Info[Att], Gain[Att]);
+	}
+
+}
+
+EvalDiscreteAtt_Discr(Att, Fp, Lp, Items, Freq, ValFreq, UnknownRate)
+	/*  ---------------  */
+	Attribute Att;ItemNo Fp, Lp;ItemCount Items; ItemCount** Freq; ItemCount* ValFreq; float* UnknownRate; {
+	ItemCount KnownItems;
+	float DiscrKnownBaseInfo_Discr(), ComputeGain_Discr(), TotalInfo();
+
+	ComputeFrequencies_Discr(Att, Fp, Lp, Freq, ValFreq, UnknownRate);
+
+	KnownItems = Items - ValFreq[0];
+
+	/*  Special case when no known values of the attribute  */
+
+	if (Items <= ValFreq[0]) {
+		Verbosity(2)
+			printf("\tAtt %s: no known values\n", AttName[Att]);
+
+		Gain[Att] = -Epsilon;
+		Info[Att] = 0.0;
+		return;
+	}
+
+	Gain[Att] = ComputeGain_Discr(DiscrKnownBaseInfo_Discr(KnownItems, MaxAttVal[Att], Freq),
+			UnknownRate[Att], MaxAttVal[Att], KnownItems, Freq, ValFreq);
+	Info[Att] = TotalInfo(ValFreq, 0, MaxAttVal[Att]) / Items;
+
+	Verbosity(2) {
+		printf("\tAtt %s", AttName[Att]);
+		Verbosity(3)
+			PrintDistribution_Discr(Att, MaxAttVal[Att], true, Freq);
+		printf("\tinf %.3f, gain %.3f\n", Info[Att], Gain[Att]);
+	}
+
+}
 /*************************************************************************/
 /*									 */
@@ -63,45 +88,72 @@
 /*************************************************************************/
 
-
-    ComputeFrequencies(Att, Fp, Lp)
-/*  ------------------  */
-    Attribute Att;
-    ItemNo Fp, Lp;
-{
-    Description Case; 
-    ClassNo c;
-    DiscrValue v;
-    ItemCount CountItems();
-    ItemNo p;
-
-    ResetFreq(MaxAttVal[Att]);
-
-    /*  Determine the frequency of each class amongst cases
-	with each possible value for the given attribute  */
-
-    ForEach(p, Fp, Lp)
-    { 
-	Case = Item[p];
-	Freq[ DVal(Case,Att) ][ Class(Case) ] += Weight[p];
-    } 
-
-    /*  Determine the frequency of each possible value for the
-	given attribute  */
-
-    ForEach(v, 0, MaxAttVal[Att]) 
-    { 
-	ForEach(c, 0, MaxClass)
-	{
-	    ValFreq[v] += Freq[v][c];
-	}
-    }
-
-    /*  Set the rate of unknown values of the attribute  */
- 
-    UnknownRate[Att] = ValFreq[0] / CountItems(Fp, Lp);
-}
-
-
-
+ComputeFrequencies(Att, Fp, Lp)
+	/*  ------------------  */
+	Attribute Att;ItemNo Fp, Lp; {
+	Description Case;
+	ClassNo c;
+	DiscrValue v;
+	ItemCount CountItems();
+	ItemNo p;
+
+	ResetFreq(MaxAttVal[Att], Freq, ValFreq);
+
+	/*  Determine the frequency of each class amongst cases
+	 with each possible value for the given attribute  */
+
+	#pragma omp parallel for private(p, Case)
+	ForEach(p, Fp, Lp) {
+		Case = Item[p];
+		#pragma omp critical
+		Freq[DVal(Case,Att)][Class(Case)] += Weight[p];
+	}
+
+	/*  Determine the frequency of each possible value for the
+	 given attribute  */
+
+	#pragma omp parallel for private(v)
+	ForEach(v, 0, MaxAttVal[Att]) {
+		ForEach(c, 0, MaxClass) {
+			ValFreq[v] += Freq[v][c];
+		}
+	}
+
+	/*  Set the rate of unknown values of the attribute  */
+
+	UnknownRate[Att] = ValFreq[0] / CountItems(Fp, Lp);
+}
+
+ComputeFrequencies_Discr(Att, Fp, Lp, Freq, ValFreq, UnknownRate)
+	/*  ------------------  */
+	Attribute Att;ItemNo Fp, Lp; ItemCount** Freq; ItemCount* ValFreq; float* UnknownRate;{
+	Description Case;
+	ClassNo c;
+	DiscrValue v;
+	ItemCount CountItems();
+	ItemNo p;
+
+	ResetFreq(MaxAttVal[Att], Freq, ValFreq);
+
+	/*  Determine the frequency of each class amongst cases
+	 with each possible value for the given attribute  */
+
+	ForEach(p, Fp, Lp) {
+		Case = Item[p];
+		Freq[DVal(Case,Att)][Class(Case)] += Weight[p];
+	}
+
+	/*  Determine the frequency of each possible value for the
+	 given attribute  */
+
+	ForEach(v, 0, MaxAttVal[Att]) {
+		ForEach(c, 0, MaxClass) {
+			ValFreq[v] += Freq[v][c];
+		}
+	}
+
+	/*  Set the rate of unknown values of the attribute  */
+
+	UnknownRate[Att] = ValFreq[0] / CountItems(Fp, Lp);
+}
 /*************************************************************************/
 /*									 */
@@ -111,29 +163,42 @@
 /*************************************************************************/
 
-
 float DiscrKnownBaseInfo(KnownItems, MaxVal)
-/*    ------------------  */
-    DiscrValue MaxVal;
-    ItemCount KnownItems;
-{
-    ClassNo c;
-    ItemCount ClassCount;
-    double Sum=0;
-    DiscrValue v;
-
-    ForEach(c, 0, MaxClass)
-    {
-	ClassCount = 0;
-	ForEach(v, 1, MaxVal)
-	{
-	    ClassCount += Freq[v][c];
-	}
-	Sum += ClassCount * Log(ClassCount);
-    }
-
-    return (KnownItems * Log(KnownItems) - Sum) / KnownItems;
-}
-
-
+	/*    ------------------  */
+	DiscrValue MaxVal;ItemCount KnownItems; {
+	ClassNo c;
+	ItemCount ClassCount;
+	double Sum = 0;
+	DiscrValue v;
+
+	//#pragma omp parallel for
+	ForEach(c, 0, MaxClass) {
+		ClassCount = 0;
+		ForEach(v, 1, MaxVal) {
+			ClassCount += Freq[v][c];
+		}
+		Sum += ClassCount * Log(ClassCount);
+	}
+
+	return (KnownItems * Log(KnownItems) - Sum) / KnownItems;
+}
+
+float DiscrKnownBaseInfo_Discr(KnownItems, MaxVal, Freq)
+	/*    ------------------  */
+	DiscrValue MaxVal;ItemCount KnownItems; ItemCount** Freq;{
+	ClassNo c;
+	ItemCount ClassCount;
+	double Sum = 0;
+	DiscrValue v;
+
+	ForEach(c, 0, MaxClass) {
+		ClassCount = 0;
+		ForEach(v, 1, MaxVal) {
+			ClassCount += Freq[v][c];
+		}
+		Sum += ClassCount * Log(ClassCount);
+	}
+
+	return (KnownItems * Log(KnownItems) - Sum) / KnownItems;
+}
 
 /*************************************************************************/
@@ -143,16 +208,13 @@
 /*************************************************************************/
 
-
-    DiscreteTest(Node, Att)
-/*  ----------  */
-    Tree Node;
-    Attribute Att;
-{
-    ItemCount CountItems();
-
-    Sprout(Node, MaxAttVal[Att]);
-
-    Node->NodeType	= BrDiscr;
-    Node->Tested	= Att;
-    Node->Errors	= 0;
-}
+DiscreteTest(Node, Att)
+	/*  ----------  */
+	Tree Node;Attribute Att; {
+	ItemCount CountItems();
+
+	Sprout(Node, MaxAttVal[Att]);
+
+	Node->NodeType = BrDiscr;
+	Node->Tested = Att;
+	Node->Errors = 0;
+}
