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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:17:17+00:00 2026-06-03T17:17:17+00:00

I have a c program as below: int a[10]; int b; for(int i =

  • 0

I have a c program as below:

int a[10];
int b;

for(int i = 0; i < 10; i++)

     function1(a[i]);
function1(b);

Now I want to parallelize all these 11 calls of function function1(). How can I do this using openmp?

I have tried

#pragma omp parallel sections
{
#pragma omp section
#pragmal omp parallel for
for(int i = 0; i < 10; i++)
     function1(a[i]);
#pragma omp section
function1(b);
}

But the above code doesn’t seem to work.
EDIT: Please read function1(b) as some different function, ie function2(b).

  • 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-03T17:17:19+00:00Added an answer on June 3, 2026 at 5:17 pm

    A simple way, that doesn’t depend on OpemMP, is to add b to the a array.
    This way, you have a single loop to parallelize.
    Just make a 11 ints long, and put the value of b in the last one.

    In a more general case (assuming the members of a are not integers, but something larger), you may want to change function1 to get a pointer. Then build another array, of 11 pointers. Set 10 to point to cells of a, the last to b.

    In an even more general case, the function called for b is a different one (possibly with entirely different parameters). In this case, you can still use one loop:

    for (i=0; i<11; i++) {
        if (i<10) {
            function1(a[i]);
        } else {
            function2(b);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have written a sample program.below: #include<iostream> #include<string> #include<set> using namespace std; int main()
As you can see below, I have Parallel.For loop. If run the program while
I have a program with a function copied below it plays a sound upon
I have a program shown below: Socket receiveSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); EndPoint
I have a Enumeration as shown in below program public class Test { public
I have a C program like the one below. I am trying to write
Below, I have a simple program which uses the CImg library (http://cimg.sourceforge.net/) which iterates
I have below five Integer variables and during the program, they are assigned some
I have the below command line arguments set for the program. argument proc is
Below I have written a sample program that I have written to learn about

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.