by Ranzeeta » Fri May 29, 2009 2:38 am
Hallo Everyone,
the following program is only the equivalent structure of my original program . In my original program, Do while loop was used . So, in order to change it to a "While" loop , i created the equivalent structure and changed the Do while loop to While loop. My final result in a sequential process is same with using "Do While" and "While" loop. But when i apply for my original program, the result is different. If anyone has an idea about it? could you please help me to parallelize this "While loop" using OpenMP.
with thanks
// calculate the first cogulated particle
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main (void)
{
double str[] = {1, 2, 3 , 4 , 5, 6 , 7 , 8 ,9,11,12,13,15,16,17,18,19,20,33,40,45,67,70};
int ntotal = 25;
double temp_sumsi=0.0;
int i= 0;
double maxr, Sipartner1;
srand (0.000001);
int ipartner1;
maxr = RAND_MAX + 1.0;
double rannum =(rand()/maxr);
while((temp_sumsi/2 < rannum) && (i <= ntotal))
// do
{
temp_sumsi = temp_sumsi + str[i];
ipartner1 = i;
i++;
/* Sipartner1 = str[ipartner1];
printf("the first partner : %d \n", Sipartner1);*/
} //while((temp_sumsi/2 < rannum) && (i <= ntotal));
Sipartner1 = str[ipartner1];
printf("the first partner : %f \n", Sipartner1);
printf (" the temp_sumsi : %f\n",temp_sumsi);
// find the second cogulated partner
double temp_sumj = 0.0;
int ipartner2;
int j =0;
double Si_partner2;
//double beta;
//do
while (((temp_sumsi- Sipartner1+temp_sumj)/2 < rannum) && (j<=ntotal))
{
ipartner2 = j;
if (j == ipartner1)
{
j++;
}
else
{
temp_sumj = temp_sumj + (5/pow(2.0,2));
j++;
//printf("temp_sumj:")
}
}
//while (((temp_sumsi- Sipartner1+temp_sumj)/2 < rannum) && (j<=ntotal));
//Si_partner2 = str[ipartner2];
printf("tempsum: %f\n",temp_sumj);
printf("second cogulated partner is : %d\n ", ipartner2);
return 0;
}