|
Luc - I wasn't trying to demonstrate the algorithm. I was demonstrating purely and simply how to convert his code into a Parallel.For.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I appreciate that, Pete. However I'm afraid you wrecked the algorithm, which isn't a very nice thing to do. When the results aren't the same, there isn't much point in measuring the speed difference, is there?
|
|
|
|
|
BTW - your code sample won't compile. The following line is the problem because of an uninitialized variable:
G[i, j] = Math.Min(G[i, j], G[i, j] + G[j, j]);
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
you're right, I replaced k's by j's, it should have been the other way around. Sorry for that.
|
|
|
|
|
hi ,i modified my code folowing that, but i get some error
folowing code running !
double[,] a, b, c;<br />
a = new double[2000, 2000];<br />
b=new double[2000,2000];<br />
c=new double[2000,2000];<br />
int s = 2000;<br />
<br />
Parallel.For(0, s, delegate(int i)<br />
{<br />
for (int j = 0; j < s; j++)<br />
{<br />
double v = 0;<br />
<br />
for (int k = 0; k < s; k++)<br />
{<br />
v += a[i, k] * b[k, j];<br />
}<br />
<br />
c[i, j] = v;<br />
}<br />
});
bu my code isn't run
Parallel.For(0, nrons, delegate(int k)<br />
{<br />
for (i = 0; i < nrons; i++)<br />
for (j = 0; j < nrons; j++)<br />
if (G[i, j]> (G[i, k] + G[k, j]) )<br />
G[i, j] =(G[i, k] + G[k, j]) ;<br />
<br />
<br />
}<br />
<br />
<br />
);<br />
why did i get error ?
|
|
|
|
|
karayel_kara wrote: my code isn't run
is not informative. does it compile? if not, what is the first error? does it run? if not, what is the first exception, with all the details? and at what line is it pointing?
anyway, your code looks all wrong. You now have three arrays. Why? You don't initialize the arrays. I see six for loops, you only need three. And the way I understand the algorithm you can not possibly run the outer loop in parallel (that was the essence of my comment to Pete too).
And please, please, please, please, please, please, show code in PRE tags, not in CODE tags.
Final remark: when all you do to the algorithm is run it in parallel, the best you can hope for is to get it N times faster, with N the number of cores, say 4. That is something, but not much. And there are no guarantees. My first experiment did run 5 times slower, because it trashed the caches all the time! (and I'm afraid that will be true for your app too).
|
|
|
|
|
Hello,
I was trying to get the content of a file in a string. I have used the following code ...
String strContent = "";
FileStream flDoc = new FileStream(m_tbxBrowser.Text, FileMode.Open, FileAccess.Read);
Byte[] bytContent = new Byte[flDoc.Length];
flDoc.Read(bytContent, 0, Convert.ToInt32(flDoc.Length));
strContent = System.Text.ASCIIEncoding.ASCII.GetString(bytContent);
But in the output, strContect some special symbols like
® is missing, and is replaced by
???
Can anyone help me to solve this? Thanks in advance.
Sebastian
|
|
|
|
|
The ASCII encoder substitutes a ? when it encounters a character code above 127. What you probably have in the file is an extended ascii character set, the most common of which is represented in Windows by the code page 1252, Single Byte Character Sets (SBCS)[^]. You can get an instance of the encoding with
Encoding coder = Encoding.GetEncoding(1252);
If you are going to write to the file I strongly suggest that you do some round trip tests to check that you have selected the correct encoding.
i.e.
Read the file
Convert to a string using the encoding
Convert the string back to bytes
Write to a new file
Check that the orignal and rewritten file are identical
Alan.
|
|
|
|
|
Hi,
i am trying remove some items from the listbox in C# windows application. but it doesn't work for me. can you please help??
below is the code snippet
foreach (object o in Lstservices.SelectedItems)
{
MessageBox.Show(Lstservices.SelectedItem.ToString());
Lstservices.SelectedItems.Remove(Lstservices.SelectedItem);
}
fttyhtrhyfytrytrysetyetytesystryrty
|
|
|
|
|
You are trying to remove items from the same listbox you are running your loop on - this is not allowed in C#.
By looking at your code, it appears you are trying to empty your list box.
Use the Clear method (on the listbox).
|
|
|
|
|
yadlaprasad wrote: Lstservices.SelectedItems.Remove(Lstservices.SelectedItem);
I don't think this'll work.
Use this instead :
Lstservices.Items.Remove(o);
|
|
|
|
|
use bellow
while (Lstservices.SelectedItems.Count>0)
{
Lstservices.Items.Remove(Lstservices.SelectedItem);
}
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
All that your code does is to remove an item from the SelectedItems collection of your ListBox (i.e. you are unselecting it), not from the ListBox itself.
To remove/delete from the listbox replace
Lstservices.SelectedItems.Remove(Lstservices.SelectedItem);
with
Lstservices.Items.Remove(Lstservices.SelectedItem);
but bear in mind that, as someone else has mentioned, C# will complain if you try this whilst iterating over the collection.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
With foreach , you are not allowed to alter the collection; you could use a while loop instead.
|
|
|
|
|
I am using this library (available on CodePlex) to retrieve and parse a web page.
When I compared the retrieved web page to the "page source" reported by a normal web browser, the two results don't match. Before I rewrite the code to use the WebClient object, I figured I'd ask if anyone else noticed this? Since he just wrote CP Vanity, any comments from Luc?
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
It's possible that the page source (when viewed in a browser) includes content generated by JavaScript, which will of course not show up in content programatically retrieved by WebClient .
/ravi
|
|
|
|
|
Hi John, I'm not familiar with HtmlAgilityPack, I've never heard of it before. I tend to use HttpWebRequest/Response when I need to get web pages; then I perform some string parsing, possibly with Regex.
|
|
|
|
|
That's perfectly normal if the page inserts dynamic content that is inserted via javascript; say it triggers data updates following the body being loaded for instance.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
There is javascript on the page. Crap. I guess I'm going to have to retrieve with WebClient, and either parse the page myself or pass it into HAP so I can use the built-in parsing it has...
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
if you navigate to the page with a System.Windows.Forms.WebBrowser it would execute the scripts and I expect the result would be available as DocumentText . AFAIK you don't have to see the WebBrowser for it to do that, so it could probably be a lone Control inside an app that isn't even a WinForms app.
|
|
|
|
|
I was just trying to avoid changing my code (I'm lazy, that's all).
Another weird aspect of HAP is that it seems to get ID names that are different from what you see in the page source from a web browser. It took me considerable time this weekend to realize that.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: I was just trying to avoid changing my code
I prefer modifying my own code a little over adding foreign code any day; more code means more problems, foreign means harder to get it right when it goes wrong.
|
|
|
|
|
Hey can you do me a favor?
Try to retrieve the date posted for one of your articles using HttpWebRequest. When I try it, I'm not getting back everything that'sdisplayed in the browser.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
if you mean getting the content of a page such as http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=648011[^] (as CP Vanity does), I did notice one of the dates for my list is off by one day. Never got around investigating it, it is still on my low-priority todo list. In my list Chris shows CP Vanity as updated on 06-APR-2010, whereas the app itself shows 05-APR-2010.
Are you suggesting:
1. you got similar phenomena?
2. it is somehow JavaScript related?
|
|
|
|
|
When I try to scrape an articles page, none of the data on the right side (date posted, date updated, views, and bookmarked) are returned when I use HtmlAgilityPack, WebClient, or HttpWebRequest. My last resort is to use the WebBrowser control to do the retrieval and then getting the html from it.
I don't know what Chris did, but this used to work. I suspect it's a javascript thing because there is a crapload of javascript in the page.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|