Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
L
Lab1
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mohammad.salama
Lab1
Commits
598b523d
Commit
598b523d
authored
Oct 28, 2023
by
mohammad.salama
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finding Primes from 1 to 10^7 using multi-threading+Finding Fibonacci (Rec+Iter)
parent
f698e009
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
127 additions
and
16 deletions
+127
-16
workspace.xml
.idea/workspace.xml
+43
-12
FibonacciSeries.java
src/main/java/FibonacciSeries.java
+40
-0
FibonacciSeriesTest.java
src/test/java/FibonacciSeriesTest.java
+40
-0
FindPrimesTest.java
src/test/java/FindPrimesTest.java
+0
-2
SearchForPrimesThreadTest.java
src/test/java/SearchForPrimesThreadTest.java
+4
-2
No files found.
.idea/workspace.xml
View file @
598b523d
...
...
@@ -4,11 +4,12 @@
<option
name=
"autoReloadType"
value=
"SELECTIVE"
/>
</component>
<component
name=
"ChangeListManager"
>
<list
default=
"true"
id=
"156428c6-b9a7-4d3a-9504-b3537029ac6a"
name=
"Changes"
comment=
"
Creating Simple Finding Primes in Interval
"
>
<change
afterPath=
"$PROJECT_DIR$/src/main/java/
SearchForPrimesThread
.java"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/src/test/java/
SearchForPrimesThread
Test.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
"
>
<change
afterPath=
"$PROJECT_DIR$/src/main/java/
FibonacciSeries
.java"
afterDir=
"false"
/>
<change
afterPath=
"$PROJECT_DIR$/src/test/java/
FibonacciSeries
Test.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"
/>
</list>
<option
name=
"SHOW_DIALOG"
value=
"false"
/>
<option
name=
"HIGHLIGHT_CONFLICTS"
value=
"true"
/>
...
...
@@ -36,14 +37,34 @@
<option
name=
"hideEmptyMiddlePackages"
value=
"true"
/>
<option
name=
"showLibraryContents"
value=
"true"
/>
</component>
<component
name=
"PropertiesComponent"
>
<![CDATA[
{
"keyToString"
: {
"RunOnceActivity.OpenProjectViewOnStart": "true"
,
"RunOnceActivity.ShowReadmeOnStart": "true"
,
"last_opened_file_path": "D:/HIAST/FIY/FS/Parallel Programming/Lab/1/PP-lec01-Threads"
<component
name=
"PropertiesComponent"
>
{
"
keyToString
"
: {
"
RunOnceActivity.OpenProjectViewOnStart
"
:
"
true
"
,
"
RunOnceActivity.ShowReadmeOnStart
"
:
"
true
"
,
"
last_opened_file_path
"
:
"
D:/HIAST/FIY/FS/Parallel Programming/Lab/1/PP-lec01-Threads
"
}
}]]>
</component>
<component
name=
"RunManager"
selected=
"JUnit.SearchForPrimesThreadTest.testSearchForPrimesThreadTest"
>
}
</component>
<component
name=
"RunManager"
selected=
"JUnit.FibonacciSeriesTest.testFibonacciSeriesRec"
>
<configuration
name=
"FibonacciSeriesTest.testFibonacciSeriesIter"
type=
"JUnit"
factoryName=
"JUnit"
temporary=
"true"
nameIsGenerated=
"true"
>
<module
name=
"Lab101"
/>
<option
name=
"PACKAGE_NAME"
value=
""
/>
<option
name=
"MAIN_CLASS_NAME"
value=
"FibonacciSeriesTest"
/>
<option
name=
"METHOD_NAME"
value=
"testFibonacciSeriesIter"
/>
<option
name=
"TEST_OBJECT"
value=
"method"
/>
<method
v=
"2"
>
<option
name=
"Make"
enabled=
"true"
/>
</method>
</configuration>
<configuration
name=
"FibonacciSeriesTest.testFibonacciSeriesRec"
type=
"JUnit"
factoryName=
"JUnit"
temporary=
"true"
nameIsGenerated=
"true"
>
<module
name=
"Lab101"
/>
<option
name=
"PACKAGE_NAME"
value=
""
/>
<option
name=
"MAIN_CLASS_NAME"
value=
"FibonacciSeriesTest"
/>
<option
name=
"METHOD_NAME"
value=
"testFibonacciSeriesRec"
/>
<option
name=
"TEST_OBJECT"
value=
"method"
/>
<method
v=
"2"
>
<option
name=
"Make"
enabled=
"true"
/>
</method>
</configuration>
<configuration
name=
"FindPrimesTest.testFindPrimes"
type=
"JUnit"
factoryName=
"JUnit"
temporary=
"true"
nameIsGenerated=
"true"
>
<module
name=
"Lab101"
/>
<option
name=
"PACKAGE_NAME"
value=
""
/>
...
...
@@ -75,6 +96,8 @@
</configuration>
<recent_temporary>
<list>
<item
itemvalue=
"JUnit.FibonacciSeriesTest.testFibonacciSeriesRec"
/>
<item
itemvalue=
"JUnit.FibonacciSeriesTest.testFibonacciSeriesIter"
/>
<item
itemvalue=
"JUnit.SearchForPrimesThreadTest.testSearchForPrimesThreadTest"
/>
<item
itemvalue=
"JUnit.SearchForPrimesThreadTest"
/>
<item
itemvalue=
"JUnit.FindPrimesTest.testFindPrimes"
/>
...
...
@@ -104,7 +127,14 @@
<option
name=
"project"
value=
"LOCAL"
/>
<updated>
1698436032981
</updated>
</task>
<option
name=
"localTasksCounter"
value=
"3"
/>
<task
id=
"LOCAL-00003"
summary=
"Finding Primes from 1 to 10^7 using multi-threading"
>
<created>
1698439374948
</created>
<option
name=
"number"
value=
"00003"
/>
<option
name=
"presentableId"
value=
"LOCAL-00003"
/>
<option
name=
"project"
value=
"LOCAL"
/>
<updated>
1698439374948
</updated>
</task>
<option
name=
"localTasksCounter"
value=
"4"
/>
<servers
/>
</component>
<component
name=
"Vcs.Log.Tabs.Properties"
>
...
...
@@ -121,6 +151,7 @@
<component
name=
"VcsManagerConfiguration"
>
<MESSAGE
value=
"first"
/>
<MESSAGE
value=
"Creating Simple Finding Primes in Interval"
/>
<option
name=
"LAST_COMMIT_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"
/>
</component>
</project>
\ No newline at end of file
src/main/java/FibonacciSeries.java
0 → 100644
View file @
598b523d
import
java.util.ArrayList
;
import
java.util.List
;
public
class
FibonacciSeries
{
private
List
<
Long
>
Fibs
;
public
FibonacciSeries
()
{
Fibs
=
new
ArrayList
<>();
Fibs
.
add
(
0L
);
Fibs
.
add
(
1L
);
}
public
long
CalculateFibsRec
(
int
number
)
{
if
(
number
<=
1
)
{
return
number
;
}
long
p1
=
CalculateFibsRec
(
number
-
1
);
long
p2
=
CalculateFibsRec
(
number
-
2
);
return
p1
+
p2
;
}
public
long
CalculateFibsIter
(
int
number
)
{
if
(
Fibs
.
size
()
>=
number
)
/// It Is Pre-Calced
{
return
Fibs
.
get
(
number
);
}
/**
* Not Pre-Calced so we start filling from where we stopped at last !!
* No Need to Re-Calc from Beginning !!!
* */
int
start
=
Fibs
.
size
();
for
(
int
i
=
start
;
i
<=
number
+
1
;
i
++)
{
Fibs
.
add
(
Fibs
.
get
(
i
-
2
)
+
Fibs
.
get
(
i
-
1
));
}
return
Fibs
.
get
(
number
);
}
}
src/test/java/FibonacciSeriesTest.java
0 → 100644
View file @
598b523d
import
junit.framework.TestCase
;
import
java.util.Scanner
;
public
class
FibonacciSeriesTest
extends
TestCase
{
private
FibonacciSeries
fibonacciSeries
;
int
Number
;
@Override
protected
void
setUp
()
{
///System.out.println("Enter Number to Get its Fibonacci");
/// Scanner scanner = new Scanner(System.in);
///Number = scanner.nextInt();
fibonacciSeries
=
new
FibonacciSeries
();
Number
=
40
;
}
public
void
testFibonacciSeriesRec
()
{
System
.
out
.
println
(
"Using Recursion : "
);
long
start
=
System
.
currentTimeMillis
();
long
ans
=
fibonacciSeries
.
CalculateFibsRec
(
Number
);
long
end
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"Ans = "
+
(
ans
));
System
.
out
.
println
(
"Time Taken : "
+
(
end
-
start
)
+
" ms"
);
}
public
void
testFibonacciSeriesIter
()
{
System
.
out
.
println
(
"Using Iterative : "
);
long
start
=
System
.
currentTimeMillis
();
long
ans
=
fibonacciSeries
.
CalculateFibsIter
(
Number
);
long
end
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"Ans = "
+
(
ans
));
System
.
out
.
println
(
"Time Taken : "
+
(
end
-
start
)
+
" ms"
);
}
}
src/test/java/FindPrimesTest.java
View file @
598b523d
...
...
@@ -16,7 +16,5 @@ public class FindPrimesTest extends TestCase
{
System.out.println(Primes1.get(i));
}*/
}
}
src/test/java/SearchForPrimesThreadTest.java
View file @
598b523d
...
...
@@ -6,10 +6,10 @@ import java.util.Scanner;
public
class
SearchForPrimesThreadTest
extends
TestCase
{
private
int
Start
=
1
;
private
int
Start
=
6000000
;
private
int
End
=
10000000
;
private
int
ThreadsNum
=
4
;
private
int
step
=
2500000
;
private
int
step
=
(
End
-
Start
+
1
)/
4
;
private
List
<
Integer
>
primes
;
...
...
@@ -49,6 +49,8 @@ public class SearchForPrimesThreadTest extends TestCase
System
.
out
.
println
(
"Time Taken = "
+
(
endTimer
-
startTimer
));
System
.
out
.
println
(
"size = "
+
(
primes
.
size
()));
/**for (int i=0 ; i<primes.size() ; i++)
{
System.out.println(primes.get(i));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment