Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lab5-metaprogramming-and-debugging-lab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Daniel Olsson
lab5-metaprogramming-and-debugging-lab
Commits
0223c528
Commit
0223c528
authored
5 years ago
by
Daniel Olsson
Browse files
Options
Downloads
Patches
Plain Diff
Lab 5
parent
0cc53e3d
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
debugging/fileutil.cpp
+11
-3
11 additions, 3 deletions
debugging/fileutil.cpp
debugging/workitems.c
+21
-2
21 additions, 2 deletions
debugging/workitems.c
julia/run.jl
+1
-1
1 addition, 1 deletion
julia/run.jl
with
33 additions
and
6 deletions
debugging/fileutil.cpp
+
11
−
3
View file @
0223c528
...
@@ -20,21 +20,29 @@ using namespace std;
...
@@ -20,21 +20,29 @@ using namespace std;
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
int
cur
=
0
;
int
cur
=
0
;
char
*
lines
[
16536
];
char
*
lines
[
35000
];
char
line
[
8
0
];
char
line
[
70
0
];
// Fix num lines, num columns, strdup-1
// Fix num lines, num columns, strdup-1
FILE
*
fin
=
fopen
(
"bible.txt"
,
"r"
);
FILE
*
fin
=
fopen
(
"bible.txt"
,
"r"
);
if
(
fin
==
NULL
){
printf
(
"File cannot be open
\n
"
);
return
0
;
}
printf
(
"Hej
\n
"
);
while
(
!
feof
(
fin
))
{
while
(
!
feof
(
fin
))
{
getline
(
line
,
fin
);
getline
(
line
,
fin
);
lines
[
cur
]
=
(
char
*
)
malloc
(
strlen
(
line
));
lines
[
cur
]
=
(
char
*
)
malloc
(
strlen
(
line
));
strcpy
(
lines
[
cur
],
line
);
strcpy
(
lines
[
cur
],
line
);
printf
(
"%d
\n
"
,
cur
);
cur
++
;
cur
++
;
}
}
fclose
(
fin
);
fclose
(
fin
);
FILE
*
fout
=
fopen
(
"copy.txt"
,
"w"
);
FILE
*
fout
=
fopen
(
"copy.txt"
,
"w"
);
for
(
int
i
=
0
;
i
<
cur
;
i
++
)
{
for
(
int
i
=
0
;
i
<
cur
;
i
++
)
{
fputs
(
lines
[
i
],
fout
);
fputs
(
lines
[
i
],
fout
);
free
(
lines
[
i
]);
}
}
fclose
(
fout
);
fclose
(
fout
);
return
0
;
return
0
;
}
}
This diff is collapsed.
Click to expand it.
debugging/workitems.c
+
21
−
2
View file @
0223c528
...
@@ -4,6 +4,8 @@
...
@@ -4,6 +4,8 @@
#include
<string.h>
#include
<string.h>
#include
<stdlib.h>
#include
<stdlib.h>
pthread_mutex_t
lock
;
typedef
struct
workitem
{
typedef
struct
workitem
{
void
(
*
fn
)(
double
*
);
void
(
*
fn
)(
double
*
);
int
current
;
int
current
;
...
@@ -14,15 +16,23 @@ typedef struct workitem {
...
@@ -14,15 +16,23 @@ typedef struct workitem {
static
void
*
launchThread
(
void
*
in
)
static
void
*
launchThread
(
void
*
in
)
{
{
int
n
;
int
n
;
workitem
*
data
=
(
workitem
*
)
in
;
workitem
*
data
=
(
workitem
*
)
in
;
volatile
int
started
=
0
;
volatile
int
started
=
0
;
while
(
!
(
started
=
data
->
started
));
while
(
!
(
started
=
data
->
started
));
while
(
1
)
{
while
(
1
)
{
pthread_mutex_lock
(
&
lock
);
n
=
data
->
current
++
;
n
=
data
->
current
++
;
if
(
n
>=
data
->
len
)
break
;
//printf("%d\n",data->current);
if
(
n
>=
data
->
len
){
pthread_mutex_unlock
(
&
lock
);
break
;
}
data
->
fn
(
&
data
->
data
[
n
]);
data
->
fn
(
&
data
->
data
[
n
]);
pthread_mutex_unlock
(
&
lock
);
}
}
//rintf("Jag är ute\n" );
return
NULL
;
return
NULL
;
}
}
...
@@ -42,7 +52,10 @@ void launchParallel(int numThreads, double *values, int len, void (*fn)(double *
...
@@ -42,7 +52,10 @@ void launchParallel(int numThreads, double *values, int len, void (*fn)(double *
for
(
int
i
=
0
;
i
<
numThreads
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numThreads
;
i
++
)
{
assert
(
0
==
pthread_create
(
&
th
[
i
],
NULL
,
launchThread
,
data
));
assert
(
0
==
pthread_create
(
&
th
[
i
],
NULL
,
launchThread
,
data
));
}
}
pthread_mutex_lock
(
&
lock
);
data
->
started
=
1
;
data
->
started
=
1
;
pthread_mutex_unlock
(
&
lock
);
for
(
int
i
=
0
;
i
<
numThreads
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numThreads
;
i
++
)
{
assert
(
th
[
i
]
&&
0
==
pthread_join
(
th
[
i
],
NULL
));
assert
(
th
[
i
]
&&
0
==
pthread_join
(
th
[
i
],
NULL
));
}
}
...
@@ -57,11 +70,17 @@ void mul2(double *d)
...
@@ -57,11 +70,17 @@ void mul2(double *d)
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
if
(
pthread_mutex_init
(
&
lock
,
NULL
)
!=
0
)
{
printf
(
"
\n
mutex init has failed
\n
"
);
return
1
;
}
double
vals
[
100
];
double
vals
[
100
];
for
(
int
i
=
0
;
i
<
100
;
i
++
)
{
for
(
int
i
=
0
;
i
<
100
;
i
++
)
{
vals
[
i
]
=
i
*
1
.
5
;
vals
[
i
]
=
i
*
1
.
5
;
}
}
launchParallel
(
4
/* Increase this if no error occurs */
,
vals
,
100
,
mul2
);
launchParallel
(
8
/* Increase this if no error occurs */
,
vals
,
100
,
mul2
);
for
(
int
i
=
0
;
i
<
100
;
i
++
)
{
for
(
int
i
=
0
;
i
<
100
;
i
++
)
{
if
(
vals
[
i
]
!=
1
.
5
*
2
*
i
)
{
if
(
vals
[
i
]
!=
1
.
5
*
2
*
i
)
{
fprintf
(
stderr
,
"Expected vals[%d] to have value %.1f, got value %.1f
\n
"
,
i
,
(
double
)
1
.
5
*
2
*
i
,
(
double
)
vals
[
i
]);
fprintf
(
stderr
,
"Expected vals[%d] to have value %.1f, got value %.1f
\n
"
,
i
,
(
double
)
1
.
5
*
2
*
i
,
(
double
)
vals
[
i
]);
...
...
This diff is collapsed.
Click to expand it.
julia/run.jl
+
1
−
1
View file @
0223c528
...
@@ -43,6 +43,6 @@ function testDoWhile()
...
@@ -43,6 +43,6 @@ function testDoWhile()
@assert
a
<
18
@assert
a
<
18
a
+=
1
a
+=
1
println
(
a
)
println
(
a
)
end
a
==
100
end
a
==
100
end
end
testDoWhile
()
testDoWhile
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment