Question

File input.txt contains 100,000 numbers separated by new line. Do the following: Write a C++ program...

File input.txt contains 100,000 numbers separated by new line. Do the following: Write a C++ program to compute the summation of these 100,000 numbers using single thread Write a C++ program to compute the summation of these 100,000 numbers using 10 threads, meaning each thread compute 10,000 summations and the main thread sum the result of the 10 threads. Using the time syscall to compare the time spent for 1.1 and 1.2 1.1 1.2 1.3 Turn Ins Source code of two programs and a short report on to answer the following question: 1. What is the run time for 1.1? 2. What is the run time for 1.2? 3. Is there a run time difference and why?

input.txt link

https://learn-us-east-1-prod-fleet01-xythos.s3.us-east-1.amazonaws.com/5b5739b6d55fd/3861301?response-content-disposition=inline%3B%20filename%2A%3DUTF-8%27%27input%25281%2529.txt&response-content-type=text%2Fplain&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20190312T204757Z&X-Amz-SignedHeaders=host&X-Amz-Expires=21600&X-Amz-Credential=AKIAIBGJ7RCS23L3LEJQ%2F20190312%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=2d90d87f5d1990624546690af1edaaa2bab9e6c32cc53ced578ca44c0d15d214

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The following code can be used to compute the summation of these 100,000 numbers using single thread

#include <chrono.h>
#include <stdlib.h>
#include <iostream.h>
#include<conio.h>
#include <iomanip.h>
//#include <string.h>
#include <fstream.h>


//using namespace std;

int main(int argc, char * argv[])
{
ifstream myfile;
myfile.open("Input.txt");
auto st=high_resolution_clock::now();
float sum = 0;
float a=0;
//myfile >> a;
int i=0;
while (!myfile.fail())
{
   myfile >> a;
   sum+=a;
}

myfile.close();
auto stp=high_resolution_clock::now();
auto dur=duration_cast<microseconds>(stp-st);
cout<<"Total time taken ="<<dur.count()<<"ms"<<endl;// displaying time taken
cout<<"Sum of integers: "<<sum<<endl; // displaying results

getch();
return 0;
}

NOTE: The given url of .txt file was not working. Thus, demo file was considered.

Add a comment
Know the answer?
Add Answer to:
File input.txt contains 100,000 numbers separated by new line. Do the following: Write a C++ program...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • File input.txt contains 100,000 numbers separated by new line. Write a C++ program to compute the...

    File input.txt contains 100,000 numbers separated by new line. Write a C++ program to compute the summation of these 100,000 numbers using 10 threads, meaning each thread compute 10,000 summations and the main thread sum the result of the 10 threads. Link to input: https://learn-us-east-1-prod-fleet01-xythos.s3.us-east-1.amazonaws.com/5b5739b6d55fd/3861301?response-content-disposition=inline%3B%20filename%2A%3DUTF-8%27%27input%25281%2529.txt&response-content-type=text%2Fplain&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20190317T013820Z&X-Amz-SignedHeaders=host&X-Amz-Expires=21600&X-Amz-Credential=AKIAIBGJ7RCS23L3LEJQ%2F20190317%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=8b1d2221f602a9dcc7b39390663d957f4fdc29f13dcf0e31e5ec15f1566b1907

  • 1. read the article: What is the function of the human appendix? Did it once have...

    1. read the article: What is the function of the human appendix? Did it once have a purpose that has since been lost?prepared by Loren G. Martin for Scientific American. link: https://learn-us-east-1-prod-fleet01-xythos.s3.us-east-1.amazonaws.com/5dae0b35612af/1719665?response-content-disposition=inline%3B%20filename%2A%3DUTF-8%27%27What%2520is%2520the%2520function%2520of%2520the%2520human%2520appendix_%2520Did%2520it%2520once%2520have%2520a%2520purpose%2520that%2520has%2520since%2520been%2520lost_%2520-%2520Scientific%2520American.pdf&response-content-type=application%2Fpdf&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20200321T164800Z&X-Amz-SignedHeaders=host&X-Amz-Expires=21599&X-Amz-Credential=AKIAZH6WM4PLTYPZRQMY%2F20200321%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=d6ff82e79be80b81d916a34ccb3d596d36ceab723eaec8cda4fbfcd44a8af212 3. answer the following question: What is the main idea of the article? Why it is difficult to know the role of the appendix in humans? Explain briefly the function that is associated with the appendix. The appendix was cataloged as a vestigial structure, meaning it lost its...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT