<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'><div dir='ltr'>
<font class="Apple-style-span" face="Tahoma" size="2">i am unable to detect an error in this code can someone please help me with this:</font><div style="font-family: Tahoma; font-size: 10pt; ">Following error is encountered when i execute this code:</div><div><div><font class="Apple-style-span" face="Tahoma" size="2">=====================================================================================</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">= BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">= EXIT CODE: 11</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">= CLEANING UP REMAINING PROCESSES</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">= YOU CAN IGNORE THE BELOW CLEANUP MESSAGES</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">====================================================
=================================</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">APPLICATION TERMINATED WITH THE EXIT STRING: Segmentation fault (signal 11)</font></div><div style="font-family: Tahoma; font-size: 10pt; "><br></div></div><div style="font-family: Tahoma; font-size: 10pt; "><br></div><div style="font-family: Tahoma; font-size: 10pt; ">code:</div><div><div><font class="Apple-style-span" face="Tahoma" size="2">long fitness(</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> /* The chromosome to be judged */</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> chromosome_t* c,</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> /* Historic prices */</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> unsigned int* h</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> )</font></div><div
><font class="Apple-style-span" face="Tahoma" size="2">{</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> int rank = MPI::COMM_WORLD.Get_rank();</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> int size = MPI::COMM_WORLD.Get_size();</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> long total_price = 0;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> long avg_price;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> long price;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> long shares = 0;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> long cash = 0;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> unsigned int t;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">
MPI_Status status;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> /*we apply parallelism here*/</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">if(rank!=0)</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">{</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> for(int t=((rank-1)*(HISTORY_LENGTH/size)); t<((rank)*( HISTORY_LENGTH/size)); t++)</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> {</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> price = h[t];</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> total_price += price;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> avg_price = total_price / (t + 1);</font></div><div><font class="Apple-style-span" face="Taho
ma" size="2"><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> /* Make price relative to average */</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> price -= avg_price;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> /* Convert price to percentage value */</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> price = price * 100 / avg_price;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> if(-price >= (long)Gray_to_bin(c->buy_price))</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> {</font></div><div><font class="Apple-style
-span" face="Tahoma" size="2"> /* Buy another share */</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> ++shares;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> cash -= (long)h[t];</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> }</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> else if(price >= (long)Gray_to_bin(c->sell_price))</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> {</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> /* Sell another share */</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> --shares;</font></div><div><
font class="Apple-style-span" face="Tahoma" size="2"> cash += (long)h[t];</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> }</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> }</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><span class="Apple-tab-span" style="white-space:pre">        </span>/* Cash out of holdings at the end for comparisons */</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> cash += shares * (long)h[t-1];</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">printf("processor %d gave cash= %d .\n",rank,cash);</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">//sendCash(0, 0,0,cash);</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> MPI_Send(&cash,1,MPI_LONG,0,0, MPI_COMM_WORLD);</font></div><div><font class=
"Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2">}</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">//MPI_Barrier(MPI_COMM_WORLD);</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">if(rank==0)</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">{</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2">long recieved_cash;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">for(int i=1; i<size; i++)</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> <span class="Apple-tab-span" style="white-space:pre">        </span>{</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> long cas
h_recieved;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><span class="Apple-tab-span" style="white-space:pre">                </span> //<span class="Apple-tab-span" style="white-space:pre">        </span>cash+=recieveCash(i, 0,0,recieved_cash);</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> MPI_Recv(&cash_recieved,1, MPI_LONG,i, 0, MPI_COMM_WORLD, &status);</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> cash+=cash_recieved;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><span class="Apple-tab-span" style="white-space:pre">                        </span> printf("master processor is taking cash from the slave processor %d ",i);</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> <span class="Apple-tab-span" style="white-
space:pre">        </span>}</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> MPI_Barrier(MPI_COMM_WORLD);</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">}</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> // MPI_Barrier(MPI_COMM_WORLD);</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"> return cash;</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">}</font></div></div>                                            </div></body>
</html>