Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6595207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:54:38+00:00 2026-05-25T17:54:38+00:00

I am working on a program that is to take the input of 15,000

  • 0

I am working on a program that is to take the input of 15,000 integers from a file. After reading the values, the thread should then create 10 threads with each thread responsible for computing the sum of their block (1,500 values each). Each thread will then print the sum of its values, and the main thread will compute the sum from all 10 threads.

What I have is mind is to read in all values and store them in an int array while using an int to keep count of the number of values read (let’s call it int values). I would then divide this number by the number of threads I would like to determine the number of values per block that each thread should have (let’s call it int block). I would then start a thread, loop through the array (int block times) while incrementing the array index count, and then start a new thread as long as the array index count does not equal the last array index.

Is this the right way of looking at this problem? Is there a simpler approach? We have been given hints to utilize pthread_create, pthread_join, pthread_exit, pthread_attr_init, pthread_attr_destroy, and pthread_setdetachstate. This is my first attempt at multithreading, so it would be great to get feedback on where in my code I should initiate and end each thread so that it is actually multithreading and not performing an individual thread multiple times. Any help would be greatly appreciated!

EDIT: Stuck on command line arguments

#include <stdio.h>

int main(int argc, char *argv[]) {
int i;
FILE *fp;
int c;

for (i = 1; i < argc; i++) {
    fp = fopen(argv[i], "r");

    if (fp == NULL) {
        fprint(stderr, "cat: can't open %s\n", argv[i]);
        continue;
    }

    while ((c = getc(fp)) != EOF) {
        putchar(c);
    }

    fclose(fp);
}

return 0;
}

I seem to have forgotten how terrible I was at I/O when we covered this section. What are the command line arguments to test my program (prob_5.c) with a given parameter?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:54:38+00:00Added an answer on May 25, 2026 at 5:54 pm

    Your plan sounds good. If I were you, I’d try to execute it and come back with specific problems should you encounter any.

    it would be great to get feedback on where in my code I should
    initiate and end each thread

    Your main thread will be creating the workers. This would be part of the loop that you describe in some detail. In all likelihood the workers will terminate by returning from their thread function.

    One thing that you shouldn’t be expecting is speed-up. In all probability your ten-worker version will be slower than its single-threaded equivalent. This has to do with the small size of the input array and the overhead of spawning threads and subsequent synchronization. Besides, as rightly pointed out by @Adam Rosenfield in the comments, the overall program is likely to be I/O-bound anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a program that take user input for two file names.
I'm working on a program that asks for input, then calculates and posts the
Working on a small program that will take a string from a user and
I'm working on a program that reads in users input as a string, which
I'm working on a program that will need to delete a folder (and then
I'm working on a program that takes in a Wavefront .obj file and eventually
I'm working on a simple program that collects and checks user-input. In addition to
I am working on a program to simply take in a user's input twice,
I'm working on a program that needs to be able to load object-properties from
Hi so I'm working on a program that is designed to take a set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.