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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:16:33+00:00 2026-05-13T09:16:33+00:00

i write a c++ code for Bubble sort algorithm and i dont know how

  • 0

i write a c++ code for Bubble sort algorithm and i dont know how to make it parallel using openmp so please help me …..
this is the code :

#include "stdafx.h"    
#include <iostream>
#include <time.h>
#include <omp.h>
using namespace std;

int a[40001];
void sortArray(int [], int);
int q=0;

int _tmain(int argc, _TCHAR* argv[])
{   
int x=40000;
int values[40000];
for (int i=0;i<x;i++)
{
    values[i]=rand();
}
cout << "Sorting Array .......\n";
clock_t start = clock();
sortArray(values, x);
 cout << "The Array Now Sorted\n";
printf("Elapsed Time : %f\n", ((double)clock() - start) / CLOCKS_PER_SEC);
cout << "\n";
}
 void sortArray(int array[], int size)  
{
  bool swap;
   int temp;
  do
  {
   swap = false;
  for (int count = 0; count < (size - 1); count++)
   {
   if (array[count] > array[count + 1])
  {
    temp = array[count];
    array[count] = array[count + 1];
    array[count + 1] = temp;
    swap = true;
  }
  }
  }while (swap);
}

it takes now about 13 seconds i tried to put
##pragma omp parallel for
before “for statment” in sortArray method and it didnt make any difference it take also about 13 second …..
so please help me as fast as you can

  • 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-13T09:16:33+00:00Added an answer on May 13, 2026 at 9:16 am

    Try this Parallel Bubble Sort algorithm:

    1.  For k = 0 to n-2
    2.  If k is even then
    3.     for i = 0 to (n/2)-1 do in parallel
    4.         If A[2i] > A[2i+1] then
    5.             Exchange A[2i] ↔ A[2i+1]
    6.  Else
    7.     for i = 0 to (n/2)-2 do in parallel
    8.         If A[2i+1] > A[2i+2] then
    9.             Exchange A[2i+1] ↔ A[2i+2]
    10. Next k
    

    Parallel Analysis

    Steps 1-10 is a one big loop that is represented n -1 times. Therefore,
    the parallel time complexity is O(n). If the algorithm, odd-numbered steps need
    (n/2) – 2 processors and even-numbered steps require
    (n/2) – 1 processors.Therefore, this needs O(n) processors.

    You can still use a swap flag check to stop the routine right before Next k.
    Of course don’t expect great speed improvement without hundreds of physical processors 🙂

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

Sidebar

Ask A Question

Stats

  • Questions 512k
  • Answers 512k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer She means that you'll get back an IEnumerable, which doesn't… May 16, 2026 at 5:44 pm
  • Editorial Team
    Editorial Team added an answer You are mixing POP and IMAP. That is not going… May 16, 2026 at 5:44 pm
  • Editorial Team
    Editorial Team added an answer As I will show, it is possible to implement the… May 16, 2026 at 5:44 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm attempting to do a simple bubble sort code to get familiar with list/string
i'm supposed to write code which when given a text file (source code) as
Most of the time I write code for embedded modules or small programs on
Right now I am trying to use selenium ide to write code that makes
I'm wondering whether there is a way to write code for Mac OS 10.5
From what I understand, in TDD you have to write a failing test first,
I found myself confronted with an interview question where the goal was to write
I am trying to add a link into the pop-up text bubble of a
I'm trying to write an event handler that fires every time a node in
I'm looking for high-resolution timing code for iPhone, in order to do some performance

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.