Polished code
This commit is contained in:
parent
29b4f6b2ef
commit
ab81ce4bc6
60
.vscode/settings.json
vendored
Normal file
60
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"iomanip": "cpp",
|
||||
"array": "cpp",
|
||||
"atomic": "cpp",
|
||||
"bit": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"cctype": "cpp",
|
||||
"charconv": "cpp",
|
||||
"chrono": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"compare": "cpp",
|
||||
"complex": "cpp",
|
||||
"concepts": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"deque": "cpp",
|
||||
"string": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"memory": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"numeric": "cpp",
|
||||
"optional": "cpp",
|
||||
"random": "cpp",
|
||||
"ratio": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp",
|
||||
"format": "cpp",
|
||||
"fstream": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"new": "cpp",
|
||||
"numbers": "cpp",
|
||||
"ostream": "cpp",
|
||||
"span": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"variant": "cpp"
|
||||
}
|
||||
}
|
||||
@ -39,17 +39,17 @@ int main(int argc, char **argv)
|
||||
setup(n, &A[0]);
|
||||
|
||||
// insert your timer code here
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> start_time = std::chrono::high_resolution_clock::now();
|
||||
auto start_time = std::chrono::high_resolution_clock::now();
|
||||
|
||||
// invoke method to perform the sum
|
||||
t = sum(n, &A[0]);
|
||||
|
||||
// insert your end timer code here, and print out elapsed time for this problem size
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> end_time = std::chrono::high_resolution_clock::now();
|
||||
auto end_time = std::chrono::high_resolution_clock::now();
|
||||
|
||||
std::chrono::duration<double> elapsed = end_time - start_time;
|
||||
|
||||
std::cout << " Elapsed time is : " << elapsed.count() << " " << std::endl;
|
||||
printf("Elapsed time is: %.2f seconds\n", elapsed.count());
|
||||
|
||||
printf(" Sum result = %lld \n", t);
|
||||
|
||||
|
||||
6
data.md
Normal file
6
data.md
Normal file
@ -0,0 +1,6 @@
|
||||
| problem size | sum_direct_time | sum_indirect_time | sum_vector_ time |
|
||||
| -- | -- | -- | -- |
|
||||
| N=8388608 | 0.00 | -- | -- |
|
||||
| N=16777216 | 0.01 | -- | -- |
|
||||
| N=33554432 | 0.01 | -- | -- |
|
||||
|
|
||||
@ -7,13 +7,13 @@
|
||||
#include <string.h>
|
||||
|
||||
|
||||
int64_t result;
|
||||
int64_t numSum;
|
||||
|
||||
void
|
||||
setup(int64_t N, uint64_t A[])
|
||||
{
|
||||
printf(" inside direct_sum problem_setup, N=%lld \n", N);
|
||||
result = 0;
|
||||
numSum = 0;
|
||||
}
|
||||
|
||||
int64_t
|
||||
@ -22,8 +22,8 @@ sum(int64_t N, uint64_t A[])
|
||||
printf(" inside direct_sum perform_sum, N=%lld \n", N);
|
||||
for (int64_t i = 0; i < N; i++)
|
||||
{
|
||||
result += i;
|
||||
numSum += i;
|
||||
}
|
||||
return result;
|
||||
return numSum;
|
||||
}
|
||||
|
||||
|
||||
@ -6,31 +6,29 @@
|
||||
#include <vector>
|
||||
#include <string.h>
|
||||
|
||||
int64_t result;
|
||||
int64_t sumResult;
|
||||
|
||||
void
|
||||
setup(int64_t N, uint64_t A[])
|
||||
void setup(int64_t N, uint64_t A[])
|
||||
{
|
||||
std::cout << "Inside setup, N = " << std::endl;
|
||||
result = 0;
|
||||
printf(" inside sum_indirect problem_setup, N=%lld \n", N);
|
||||
sumResult = 0;
|
||||
|
||||
for (int64_t i = 0; i < N; i++)
|
||||
{
|
||||
A[i] = lrand48() % N;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int64_t
|
||||
sum(int64_t N, uint64_t A[])
|
||||
{
|
||||
int64_t indx = A[0];
|
||||
printf(" inside sum_indirect perform_sum, N=%lld \n", N);
|
||||
int64_t counter = A[0];
|
||||
for (int64_t i = 0; i < N; i++)
|
||||
{
|
||||
result += indx;
|
||||
indx = A[indx];
|
||||
sumResult += counter;
|
||||
counter = A[counter];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return sumResult;
|
||||
}
|
||||
|
||||
@ -6,13 +6,13 @@
|
||||
#include <vector>
|
||||
#include <string.h>
|
||||
|
||||
int64_t result;
|
||||
int64_t numSum;
|
||||
|
||||
void
|
||||
setup(int64_t N, uint64_t A[])
|
||||
{
|
||||
printf(" inside sum_vector problem_setup, N=%lld \n", N);
|
||||
result = 0;
|
||||
numSum = 0;
|
||||
for (int64_t i = 0; i < N; i++)
|
||||
{
|
||||
A[i] = i;
|
||||
@ -26,9 +26,9 @@ sum(int64_t N, uint64_t A[])
|
||||
printf(" inside sum_vector perform_sum, N=%lld \n", N);
|
||||
for (int64_t i = 0; i < N; i++)
|
||||
{
|
||||
result += A[i];
|
||||
numSum += A[i];
|
||||
}
|
||||
|
||||
return result;
|
||||
return numSum;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user