Commit b125fd89 authored by mohammad.salama's avatar mohammad.salama

Finding Primes from 1 to 10^7 using multi-threading+Finding Fibonacci...

Finding Primes from 1 to 10^7 using multi-threading+Finding Fibonacci (Rec+Iter)+ Fibonacci with Threads (simple)
parent 598b523d
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
......@@ -4,12 +4,14 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="156428c6-b9a7-4d3a-9504-b3537029ac6a" name="Changes" comment="Finding Primes from 1 to 10^7 using multi-threading">
<change afterPath="$PROJECT_DIR$/src/main/java/FibonacciSeries.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/test/java/FibonacciSeriesTest.java" afterDir="false" />
<list default="true" id="156428c6-b9a7-4d3a-9504-b3537029ac6a" name="Changes" comment="Finding Primes from 1 to 10^7 using multi-threading+Finding Fibonacci (Rec+Iter)">
<change afterPath="$PROJECT_DIR$/.idea/encodings.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/uiDesigner.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/FibonacciSeriesService.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/FibonacciSeriesThread.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/test/java/FibonacciSeriesThreadTest.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/test/java/FindPrimesTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/FindPrimesTest.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/test/java/SearchForPrimesThreadTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/SearchForPrimesThreadTest.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/test/java/FibonacciSeriesTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/FibonacciSeriesTest.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......@@ -37,14 +39,15 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;last_opened_file_path&quot;: &quot;D:/HIAST/FIY/FS/Parallel Programming/Lab/1/PP-lec01-Threads&quot;
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"last_opened_file_path": "D:/HIAST/FIY/FS/Parallel Programming/Lab/1/PP-lec01-Threads"
}
}</component>
<component name="RunManager" selected="JUnit.FibonacciSeriesTest.testFibonacciSeriesRec">
}]]></component>
<component name="RunManager" selected="JUnit.FibonacciSeriesThreadTest.testFibonacciThread">
<configuration name="FibonacciSeriesTest.testFibonacciSeriesIter" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="Lab101" />
<option name="PACKAGE_NAME" value="" />
......@@ -65,11 +68,11 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="FindPrimesTest.testFindPrimes" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<configuration name="FibonacciSeriesThreadTest.testFibonacciThread" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="Lab101" />
<option name="PACKAGE_NAME" value="" />
<option name="MAIN_CLASS_NAME" value="FindPrimesTest" />
<option name="METHOD_NAME" value="testFindPrimes" />
<option name="MAIN_CLASS_NAME" value="FibonacciSeriesThreadTest" />
<option name="METHOD_NAME" value="testFibonacciThread" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
......@@ -96,11 +99,11 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="JUnit.FibonacciSeriesTest.testFibonacciSeriesRec" />
<item itemvalue="JUnit.FibonacciSeriesThreadTest.testFibonacciThread" />
<item itemvalue="JUnit.FibonacciSeriesTest.testFibonacciSeriesIter" />
<item itemvalue="JUnit.FibonacciSeriesTest.testFibonacciSeriesRec" />
<item itemvalue="JUnit.SearchForPrimesThreadTest.testSearchForPrimesThreadTest" />
<item itemvalue="JUnit.SearchForPrimesThreadTest" />
<item itemvalue="JUnit.FindPrimesTest.testFindPrimes" />
</list>
</recent_temporary>
</component>
......@@ -134,7 +137,14 @@
<option name="project" value="LOCAL" />
<updated>1698439374948</updated>
</task>
<option name="localTasksCounter" value="4" />
<task id="LOCAL-00004" summary="Finding Primes from 1 to 10^7 using multi-threading+Finding Fibonacci (Rec+Iter)">
<created>1698480438448</created>
<option name="number" value="00004" />
<option name="presentableId" value="LOCAL-00004" />
<option name="project" value="LOCAL" />
<updated>1698480438448</updated>
</task>
<option name="localTasksCounter" value="5" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
......@@ -152,6 +162,7 @@
<MESSAGE value="first" />
<MESSAGE value="Creating Simple Finding Primes in Interval" />
<MESSAGE value="Finding Primes from 1 to 10^7 using multi-threading" />
<option name="LAST_COMMIT_MESSAGE" value="Finding Primes from 1 to 10^7 using multi-threading" />
<MESSAGE value="Finding Primes from 1 to 10^7 using multi-threading+Finding Fibonacci (Rec+Iter)" />
<option name="LAST_COMMIT_MESSAGE" value="Finding Primes from 1 to 10^7 using multi-threading+Finding Fibonacci (Rec+Iter)" />
</component>
</project>
\ No newline at end of file
import java.lang.reflect.Field;
public class FibonacciSeriesService
{
public long FibonacciSeriesThreadCalc(long number)
{
if (number <= 1)
{
return number;
}
FibonacciSeriesThread fibonacciSeriesThread1 = new FibonacciSeriesThread(number-1);
FibonacciSeriesThread fibonacciSeriesThread2 = new FibonacciSeriesThread(number-2);
fibonacciSeriesThread1.start();
fibonacciSeriesThread2.start();
try
{
fibonacciSeriesThread1.join();
fibonacciSeriesThread2.join();
}
catch (InterruptedException e)
{
throw new RuntimeException(e);
}
long p1 = fibonacciSeriesThread1.getAns();
long p2 = fibonacciSeriesThread2.getAns();
return p1+p2;
}
}
import java.util.ArrayList;
public class FibonacciSeriesThread extends Thread
{
private long Ans;
private long number;
public FibonacciSeriesThread(long number)
{
Ans = 0;
this.number = number;
}
public long CalculateFibsRec(long number)
{
if (number <= 1)
{
return number;
}
long p1 = CalculateFibsRec(number-1);
long p2 = CalculateFibsRec(number-2);
return p1+p2;
}
public long getAns()
{
return Ans;
}
@Override
public void run()
{
this.Ans = CalculateFibsRec(number);
}
}
......@@ -14,7 +14,7 @@ public class FibonacciSeriesTest extends TestCase
/// Scanner scanner = new Scanner(System.in);
///Number = scanner.nextInt();
fibonacciSeries = new FibonacciSeries();
Number = 40;
Number = 45;
}
public void testFibonacciSeriesRec()
......
import junit.framework.TestCase;
public class FibonacciSeriesThreadTest extends TestCase
{
private FibonacciSeriesService fibonacciSeriesService;
public void testFibonacciThread()
{
long num = 45;
fibonacciSeriesService= new FibonacciSeriesService();
long start = System.currentTimeMillis();
long ans = fibonacciSeriesService.FibonacciSeriesThreadCalc(num);
long end = System.currentTimeMillis();
System.out.println("Ans = " + (ans));
System.out.println("Time Taken = " + (end-start));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment