Monday, April 30, 2012

Parallel delaunay triangulation naive algorithm

The following code(Pg.187,Computational Geom in C by Rourke) takes same time to run serially as well as in parallel(2 proc).
Please help me identify the problem.
Here's the parallel portion



int chunk;
chunk=10;
#pragma omp parallel private(i,j,k,xn,yn,zn)
{
#pragma omp for schedule(static,chunk)
for(i=0;i<n-2;i++)
{
for(j=i+1;j<n;j++)
for(k=i+1;k<n;k++)
if(j!=k)
{
xn=(y[j]-y[i])*(z[k]-z[i])-(y[k]-y[i])*(z[j]-z[i]);
yn=(x[k]-x[i])*(z[j]-z[i])-(x[j]-x[i])*(z[k]-z[i]);
zn=(x[j]-x[i])*(y[k]-y[i])-(x[k]-x[i])*(y[j]-y[i]);
if(flag=(zn<0))
for(m=0;m<n;m++)
flag=flag && ((x[m]-x[i])*xn + (y[m]-y[i])*yn + (z[m]-z[i])*zn <=0);
if (flag)
printf("%d\t%d\t%d\n",i,j,k);
}
}
}




Response.Redirect behaves different from within UpdatePanel

Everywhere in my web application i use redirects like these:



Response.Redirect("~/SearchResults.aspx", true); 


And this always takes me to the right page. http://localhost/myapp/SearchResults.aspx



But now i'm doing this in the onclick event of a button that sits in an ASP.NET UpdatePanel and it tries to bring me to the following address:
http://localhost/myapp/%2fmyapp%2fSearchResults.aspx



Does anyone have an idea how to fix this?





UITableView with Core Data ordered by time, not alphabetically

I'm working on an app that uses Core Data and a UITableView. What I've noticed is that when I add a new TableView entry, the cells seem to order alphabetically. Is there a way to make it so the cells are ordered by the time I add them (from top to bottom) rather than by the alphabet. Thanks!





MYSQL ordering columns in my query

I have been working on trying to get a bunch of data to work in a table structure displayed neatly using PHP, and I must say I am having a difficult time. I have finally been able to call the columns so that in case I add a field it will always add it in my table, and I hope for this to be very easily managed. However, when I initially set up the table, I put it in a random order. Now when I come use the DESCRIBE table it gives them to me in exact order, and I cannot find a way to organize them better. It would not make sense to say have month/year at the end of the database for my form that I have.



<?php 
require 'connect.php';
?>
<h3>Monthly Finances | <a href="new.php">Add New Month</a> </h3>
<table border="1" bordercolor ="#000000">
<tr>
<?php
$columns = "DESCRIBE `month` ";
if($query_run_columns = mysql_query($columns)){
$columnNames = array();
while($column = mysql_fetch_assoc($query_run_columns)){
echo '<th>'.$column['Field'].'</th>';
}
}else{
echo'sql error';
}

?>


<?php
$gatherdata = "SELECT `month`, `year`,`rent`,`electric`,`cable`,`cellphone`,`renters` FROM `month` ";
if($query_run = mysql_query($gatherdata)){

while($row = mysql_fetch_assoc($query_run)){
$rent = $row['rent'];
$electric = $row['electric'];
$cable = $row['cable'];
$cellphone = $row['cellphone'];
$renters = $row['renters'];
$month = $row['month'];
$year = $row['year'];

echo '<tr>';
echo '<td align="center">'.$month.'</td>';
echo '<td algin="center">'.$year.'</td>';
echo '<td align="center">'.$rent.'</td>';
echo '<td align="center">'.$electric.'</td>';
echo '<td align="center">'.$cable.'</td>';
echo '<td align="center">'.$cellphone.'</td>';
echo '<td align="center">'.$renters.'</td>';
echo '</tr>';
}
}else{
echo 'query error';
}
?>
<br>View by month
</table>
<form action="index.php" method="GET">
<select name="months" value="all">
<?php
$gathermonths = "SELECT `month`, `year` FROM `month";

if($query_month_selector = mysql_query($gathermonths)){
while($month_row = mysql_fetch_assoc($query_month_selector)){
$month = $month_row['month'];
$year = $month_row['year'];

echo '<option value="'.$month.' '.$year.'">' .$month.' '.$year.'</option>';
}
}
echo $_GET['months'];
?>
<input type="submit" value="View Selected Date"></input>
</select>
</form>


My code is very far from complete, or orderly but I have been slacking on this project and I will clean it up more when I have more time. But if you could please give me a hand on an efficient organizational method that would be appreciated.





Android: Append not shown ActionItems to Icon instead of Context Menu

I found an example how to use a context menu with actionBar. This example waits for clicks on the phones menu button. But I want to have it appended to the icon or better the activity name. thanks



  public class menu extends Activity {

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_fragen, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
..




StringBuilder Append vs AppendFormat efficiency in C#

Which is more efficient in C#, 1 or 2?



StringBuilder sb = new StringBuilder();
sb.Append("my string " + myVar + " my string"); // 1
sb.AppendFormat("my string {0} my string", myVar); // 2


I'm guessing that the question could also be rephrased:



string y = "my string " + myVar + " my string";              // 1
string x = String.Format("my string {0} my string", myVar); // 2




Ruby is very slow

I have a PC with 2 processors of 2GHz and 4go of ram. I use RVM with ruby-1.9.3-p194-perf and rails 3.2.3. When I load my rails application, it take a few time and I think it's not normal.



This is some example :



time rails new speed_test
...
real 0m7.240s
user 0m4.484s
sys 0m0.184s

time rails g scaffold Articles title:string description:text
...
real 0m4.910s
user 0m4.052s
sys 0m0.348s

time rake db:migrate
...
real 0m4.172s
user 0m3.716s
sys 0m0.244s

time rake
...
real 0m15.981s
user 0m14.045s
sys 0m1.048s


This is some short commands but, with some hundred of tests, it's very long, even with spork.



Do you have a solution?



Thanks a lot!