Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F88610312
assignment2.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Oct 19, 18:01
Size
1 KB
Mime Type
text/x-c
Expires
Mon, Oct 21, 18:01 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
21797652
Attached To
R10834 Project_multiproc
assignment2.c
View Options
/*
============================================================================
Filename : assignment2.c
Author : Arash Pourhabibi, Hussein Kassir
============================================================================
*/
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "utility.h"
#include "algorithm.c"
int
main
(
int
argc
,
const
char
*
argv
[])
{
int
threads
,
length
,
iterations
;
double
time
;
if
(
argc
!=
5
)
{
printf
(
"Invalid input!
\n
Usage: ./assignment2 <threads> <length> <iterations> <output_filname>
\n
"
);
return
1
;
}
else
{
threads
=
atoi
(
argv
[
1
]);
length
=
atoi
(
argv
[
2
]);
iterations
=
atoi
(
argv
[
3
]);
if
(
length
%
2
!=
0
)
{
printf
(
"Invalid input! Array length must be even
\n
"
);
return
1
;
}
}
//Allocate a two-dimensional array
double
*
input
=
malloc
(
sizeof
(
double
)
*
length
*
length
);
double
*
output
=
malloc
(
sizeof
(
double
)
*
length
*
length
);
//Initialize the array
init
(
input
,
length
);
init
(
output
,
length
);
//Start timer
set_clock
();
//Optimize the following function
simulate
(
input
,
output
,
threads
,
length
,
iterations
);
//Stop timer
time
=
elapsed_time
();
//Report time required for n iterations
printf
(
"Running the algorithm with %d threads on %d by %d array for %d iterations took %.4g seconds
\n
"
,
threads
,
length
,
length
,
iterations
,
time
);
if
(
iterations
%
2
==
0
){
double
*
temp
=
input
;
input
=
output
;
output
=
temp
;
}
//Save array in filelength if the output is not /dev/null
// idea: do not save if not needed
if
(
strcmp
(
argv
[
4
],
"/dev/null"
)
!=
0
)
save
(
output
,
length
,
argv
[
4
]);
//Free allocated memory
free
(
input
);
free
(
output
);
return
0
;
}
Event Timeline
Log In to Comment