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 8852947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:31:40+00:00 2026-06-14T13:31:40+00:00

I am writing a program in c++ in visual studio to be able to

  • 0

I am writing a program in c++ in visual studio to be able to handle a line at a park. I have all of my customers in a line at the park and I want to be able to service them using multithreading with openmp.

When I put the pragma and such in, I have multiple threads servicing the same customer at the same time for each and every customer I create, not what I want.

I want for example, if I had two threads and four customers, that thread one to do customer one while thread 2 does customer 2. Then I would like thread 1 to do customer 3 and thread 2 customer 4 at the same time. I don’t know if its possible or if there is a better way, but I need to use openMP.

  • 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-06-14T13:31:41+00:00Added an answer on June 14, 2026 at 1:31 pm

    You can associate each for iteration as a customer and assign them (costumer) to threads in a static manner.

    #pragma omp parallel for schedule(static, CHUNKSIZE)
    for(i = 0; i < customer_max; i++)
    {
     // do something with customers 
    
    }
    

    static: In this distribution threads have their work statically precalculated before the execution of the actual loop. The iterations are divided among threads equally by default. However, if you specify an integer for the parameter CHUNKSIZE the distribution will allocate chunks of size CHUNKSIZE of contiguous iterations to threads.

    In your example with 2 threads and 4 customers, you would use CHUNKSIZE = 1. Thus, the thread 0 will execute both costumer 0 and 2, while thread 2 would execute costumer 1 and 3.

    If you do not specify the CHUNKSIZE, thread 0 would execute the first 2 customers and the thread 1 the remaining 2.

    In another hand, if you prefer that each thread serve the customers in a dynamic manner you can use a dynamic distribution.

        #pragma omp parallel for schedule(dynamic)
        for(i = 0; i < customer_max; i++)
        {
         // do something with customers 
    
        }
    

    The dynamic schedule is appropriate for the case of a for with iterations that perform work that time-wise can vary a lot. Analogously in your case, If you have consumers who take different times to be served.

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

Sidebar

Related Questions

Okay, I have a WinForms C# program I am writing in Visual Studio 2010
I'm writing a program that includes a secondary form using C++/CLI in Visual Studio
I'm writing windows program with C and Visual Studio. I have to map a
I am writing a program in C++ using Visual studio, what I need to
I am writing a program in C# using Visual Studio 2010 and gets an
I am writing a program in C for windows using visual studio 2010. I
I am writing a program in C# using Visual Studio 2010 and gets an
I am writing a small console application in C# using Visual Studio. I want
I'm writing an MPI program (Visual Studio 2k8 + MSMPI) that uses Boost::thread to
I am writing a small program in Visual Studio 11 (beta) that a console

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.