Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Jonnty
Aug 2, 2007

The enemy has become a flaming star!

Zombywuf posted:

Depressing isn't it?

This is what Java actually believes.

But java doesn't have function pointers!

Adbot
ADBOT LOVES YOU

Woodsy Owl
Oct 27, 2004
I'm working on a pet project and I've run in to a bit of trouble. What I am trying to do is take the right ascension and declination of a celestial object and transpose those angles into Cartesian space.

The tricky bit is trying to figure out the maths for the translations. The declination angle can be used to determine a point on the z-y plane, but then I need to rotate that point around the y-axis given the right ascension angle.

Figure that I am trying to plot a sphere in x-y-z space.

Any ideas?

qntm
Jun 17, 2009

Woodsy Owl posted:

I'm working on a pet project and I've run in to a bit of trouble. What I am trying to do is take the right ascension and declination of a celestial object and transpose those angles into Cartesian space.

The tricky bit is trying to figure out the maths for the translations. The declination angle can be used to determine a point on the z-y plane, but then I need to rotate that point around the y-axis given the right ascension angle.

Figure that I am trying to plot a sphere in x-y-z space.

Any ideas?

Well, for starters, you also need a radius before you can plot that in Cartesian space. Let's assume a radius of r, a right ascension of a (0 to 2*pi) and a declination of d (-pi/2 to pi/2). Let's also assume that d=0 leaves you in the x-y plane, and a=0 leaves you pointed directly along the x-axis in the positive direction.

With no rotations applied at all, your position is (x=r, y=0, z=0).

Applying right ascension, your position is now (x=r*cos(a), y=r*sin(a), z=0).

Applying declination, your position is now (x=r*cos(a)*cos(d), y=r*sin(a)*cos(d), z=r*sin(d)).

I have a neat little diagram here which I can scan and upload if need be.

haiQt
Nov 4, 2009
Small XHTML/CSS question here.

If you go to http://de-raedt.eu/fomsitenew/ and hover over the menu, the submenu background (red in this case for troubleshooting) should start at the bottom white border of the navigation. In Chrome this works fine, but if you hover over it in Firefox the background is nudged upwards 3 pixels, which makes it end up kind of inside the navigation. Screenshot below for comparison!

http://gyazo.com/9841bcbd058c7ffccfaab37f08325411

Mthrboard
Aug 24, 2002
Grimey Drawer
I've been banging my head against this all morning. I'm trying to write a simple GreaseMonkey script to remove one row from a table. I've tried several variations of code, but nothing will do what I want. Here's the latest revision, based on searches in the GreaseMonkey forums.

code:
var foo = document.evaluate('//tr/(td[2])[contains(text(),"CHKCARDAMAZON.COM")]', document, null, 6, null);

alert(foo.snapshotLength);

for ( var i = foo.snapshotLength - 1 ; ~i ; --i )
{
	var bar = foo.snapshotItem(i);
	bar.parentNode.removeChild(bar);
}
Here's the html from the website:

code:
<tr><td class="date" headers="pendingHeader dateHeader">06/16/11</td>
<td class="text" headers="pendingHeader descriptionHeader">CHKCARDAMAZON.COM
<span class="noprint"></span></td>
<td class="amount" headers="pendingHeader depositsConsumerHeader">&nbsp;</td>
<td class="amount" headers="pendingHeader withdrawalsConsumerHeader">$122.41</td></tr>
<tr><td class="date" headers="pendingHeader dateHeader">06/16/11</td>
<td class="text" headers="pendingHeader descriptionHeader">CHKCARDCASH WISE
<span class="noprint"></span></td>
<td class="amount" headers="pendingHeader depositsConsumerHeader">&nbsp;</td>
<td class="amount" headers="pendingHeader withdrawalsConsumerHeader">$20.07</td></tr>
Can anyone tell me what I'm doing wrong? I just need to hide this one line from my wife until her birthday next month, but I can't want to block access to the whole website. Thanks in advance for any help.

Woodsy Owl
Oct 27, 2004

qntm posted:

Well, for starters, you also need a radius before you can plot that in Cartesian space. Let's assume a radius of r, a right ascension of a (0 to 2*pi) and a declination of d (-pi/2 to pi/2). Let's also assume that d=0 leaves you in the x-y plane, and a=0 leaves you pointed directly along the x-axis in the positive direction.

With no rotations applied at all, your position is (x=r, y=0, z=0).

Applying right ascension, your position is now (x=r*cos(a), y=r*sin(a), z=0).

Applying declination, your position is now (x=r*cos(a)*cos(d), y=r*sin(a)*cos(d), z=r*sin(d)).

I have a neat little diagram here which I can scan and upload if need be.

I figured out an elegant solution. When I am computing the position on the x-z plane I need to multiply by cos(dec) to scale the vector components.

Essentially what I am doing is drawing concentric rings about the y-axis and scaling them accordingly.

cannibustacap
Jul 7, 2003

Brrrruuuuuiinnssss
I am looking to write some Java classes/methods in Eclipse and have them run in my team's Visual Studio C++ application.

Now, I know I can just make a Jar file out of my functions and run them, but the Jar files execute the static void main---which means it will not return any values.

I would like be able to run my java methods in C++ and have it return values.

So I am wondering what the best way to do this is. I understand it may come down to some type of shell, but I just can't figure out what.

I'd like it to hopefully be very simple, not require a lot of steps. Something standard and straightforward (hard to find on Google).


Also, ideally, is there a way to get my C++ functions to talk with Java also? Specifically, I compile my Matlab code into C++ shared libraries, so I have the working .DLL's and .H files, but without some kind of shell, they won't work with Java.

I understand this may interfere with cross-compatibility. That is okay, not an issue. Just want to get this one thing happening.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


cannibustacap posted:

I am looking to write some Java classes/methods in Eclipse and have them run in my team's Visual Studio C++ application.

Now, I know I can just make a Jar file out of my functions and run them, but the Jar files execute the static void main---which means it will not return any values.

I would like be able to run my java methods in C++ and have it return values.

So I am wondering what the best way to do this is. I understand it may come down to some type of shell, but I just can't figure out what.

I'd like it to hopefully be very simple, not require a lot of steps. Something standard and straightforward (hard to find on Google).


Also, ideally, is there a way to get my C++ functions to talk with Java also? Specifically, I compile my Matlab code into C++ shared libraries, so I have the working .DLL's and .H files, but without some kind of shell, they won't work with Java.

I understand this may interfere with cross-compatibility. That is okay, not an issue. Just want to get this one thing happening.

The easiest method by far will be to have one process kick off the other from the command line, and read the appropriate output from a file.

Edit: You can look into other interprocess communication mechanisms like sockets or shared memory, but all of them are basically a more complicated version of reading/writing from files.

Woodsy Owl
Oct 27, 2004

qntm posted:

Well, for starters, you also need a radius before you can plot that in Cartesian space. Let's assume a radius of r, a right ascension of a (0 to 2*pi) and a declination of d (-pi/2 to pi/2). Let's also assume that d=0 leaves you in the x-y plane, and a=0 leaves you pointed directly along the x-axis in the positive direction.

With no rotations applied at all, your position is (x=r, y=0, z=0).

Applying right ascension, your position is now (x=r*cos(a), y=r*sin(a), z=0).

Applying declination, your position is now (x=r*cos(a)*cos(d), y=r*sin(a)*cos(d), z=r*sin(d)).

I have a neat little diagram here which I can scan and upload if need be.

Thanks for your help but I worked this out on paper last night and confirmed functionality today.

x = cos(declination) * cos(ascension) * scale_factor
y = sin(declination) * scale_factor
z = cos(declination) * sin(ascension) * scale_factor

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

cannibustacap posted:

Also, ideally, is there a way to get my C++ functions to talk with Java also? Specifically, I compile my Matlab code into C++ shared libraries, so I have the working .DLL's and .H files, but without some kind of shell, they won't work with Java.
In this specific case the simplest method is to pay a few thousand dollars for a Builder JA license.

nielsm
Jun 1, 2009



cannibustacap posted:

Also, ideally, is there a way to get my C++ functions to talk with Java also? Specifically, I compile my Matlab code into C++ shared libraries, so I have the working .DLL's and .H files, but without some kind of shell, they won't work with Java.

Java Native Interface lets you call native code from Java. It's probably a lot of effort to make it work well.

cannibustacap
Jul 7, 2003

Brrrruuuuuiinnssss

ultrafilter posted:

The easiest method by far will be to have one process kick off the other from the command line, and read the appropriate output from a file.

Edit: You can look into other interprocess communication mechanisms like sockets or shared memory, but all of them are basically a more complicated version of reading/writing from files.

Thanks, my only concern with just making a simple .JAR file and run it through a command line is that it won't return values.

I wish I could do a "static int main(String[] args)" type of thing and return output codes, but I can't...

Or can I?

As for Java Builder for Matlab, I agree, but I don't think my employer is going to buy it. :-/

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

cannibustacap posted:

Thanks, my only concern with just making a simple .JAR file and run it through a command line is that it won't return values.

I wish I could do a "static int main(String[] args)" type of thing and return output codes, but I can't...

Or can I?

I think that if you do a System.exit(#number) that the number is returned to the process that invokes the jar. Or else you could println the stuff you want and simply read the output stream from your C++ app.

cannibustacap
Jul 7, 2003

Brrrruuuuuiinnssss

MEAT TREAT posted:

I think that if you do a System.exit(#number) that the number is returned to the process that invokes the jar. Or else you could println the stuff you want and simply read the output stream from your C++ app.

Hmm.. I thought System.exit will destroy the calling program as well?

That is what happens when I run my java methods directly from matlab at least... Hmm, maybe if the System.exit destroys the Runtime instance only, it won't hurt the C++ app that calls it?

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
System.exit can only affect the JVM.

Zero VGS
Aug 16, 2002
ASK ME ABOUT HOW HUMAN LIVES THAT MADE VIDEO GAME CONTROLLERS ARE WORTH MORE
Lipstick Apathy
Hey guys, as the poor IT schmuck at my company I'm charged with switching 300+ DHCP-using Windows XP workstations into Static IPs, preserving the same settings they had in DHCP. I'm sure there's a VB script or .bat file for something like this but I've been Googling for hours and anything I can find is trying to go from Static to DHCP, not regress backwards. I don't have two days to copy and paste everything from ipconfig on every workstation.

If someone can find/write me a fully automated script that I can deploy with GPO I'll buy you platinum or paypal :10bux:.

rolleyes
Nov 16, 2006

Sometimes you have to roll the hard... two?
I can't help with your query but I can think of another one: why the hell would you want to do that?!

Zero VGS
Aug 16, 2002
ASK ME ABOUT HOW HUMAN LIVES THAT MADE VIDEO GAME CONTROLLERS ARE WORTH MORE
Lipstick Apathy
Basically we have to remove a DHCP server and there's no guarantee we can get a new one up due to the way our switches are configured, and we're not allowed to touch our switches. It's really stupid.

I did find this .vbs to set all network connections to DHCP:

code:
strComputer = "." 
Set objWMIService = GetObject("winmgmts:" _ 
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
 
Set colNetAdapters = objWMIService.ExecQuery _ 
    ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") 
  
For Each objNetAdapter In colNetAdapters 
    errEnable = objNetAdapter.EnableDHCP() 
Next
Can the "EnableDHCP" command be changed to "EnableStatic" and the script be expanded to supply whatever IP/Subnet/Gateway/DNS was in DHCP?

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

I would suggest asking in the PowerShell thread; I don't have anything to back that up other than apparently PowerShell can do everything.

csammis
Aug 26, 2003

Mental Institution

Zero VGS posted:

I did find this .vbs to set all network connections to DHCP:

Can the "EnableDHCP" command be changed to "EnableStatic"

Did you look at the VBScript object documentation? There is an EnableStatic method that takes an IP address and a subnet. Collect the current IP and subnet on the machine before calling EnableStatic and use those as parameters.

e: The comments on the EnableStatic method page are kinda funny. "I ran this remotely and it gave an error code! :saddowns:"

mik
Oct 16, 2003
oh
Just to get a final, straight answer:

I have a for loop that's thousands of iterations long. Inside the for loop it's pretty basic math, some very basic if/then logic, and each iteration is independent of each other. This is pretty much the perfect application for GPGPU computing, correct?

ChiralCondensate
Nov 13, 2007

what is that man doing to his colour palette?
Grimey Drawer

mik posted:

Just to get a final, straight answer:

I have a for loop that's thousands of iterations long. Inside the for loop it's pretty basic math, some very basic if/then logic, and each iteration is independent of each other. This is pretty much the perfect application for GPGPU computing, correct?
It's embarrassingly parallel.

baquerd
Jul 2, 2007

by FactsAreUseless

mik posted:

Just to get a final, straight answer:

I have a for loop that's thousands of iterations long. Inside the for loop it's pretty basic math, some very basic if/then logic, and each iteration is independent of each other. This is pretty much the perfect application for GPGPU computing, correct?

If you can tell it the bolded part or it can figure that out then yes.

JawnV6
Jul 4, 2004

So hot ...
Depending on how much of it there is, that "if/then logic" might tank his performance on a GPU. Branches are still handled by predicate-based execution, right?

shrughes
Oct 11, 2008

(call/cc call/cc)

JawnV6 posted:

Depending on how much of it there is, that "if/then logic" might tank his performance on a GPU. Branches are still handled by predicate-based execution, right?

Uh, worst case scenario it executes both branches and conditional-moves the result, right? Maybe performance could be divide by two..

JawnV6
Jul 4, 2004

So hot ...

shrughes posted:

Uh, worst case scenario it executes both branches and conditional-moves the result, right? Maybe performance could be divide by two..

The hardware's significantly dumber than you're imagining. Every thread executes every instruction, divergent 'branches' executing are handled by predicates at the instruction level.

For NVidia's CUDA, you have groups of 32 threads called a 'warp' that have identical code. So if you've got something like:
code:
if(cond){
instruction1
instruction2
} else {
instruction3
instruction4
}
it'll be flattened into something like this:
code:
predicate = if(cond)
if(predicate) instruction1
if(predicate) instruction2
if(!predicate) instruction3 
if(!predicate) instruction4
So when this lands on a GPU, if anyone takes that branch then every single execution unit is going through all 5 instructions. 40% of your potential throughput is wasted because of that if/then.

It's easy to assume you couldn't do worse than 40-50%, but it's not hard to get a case where this will really hurt you. Maybe his if/then logic is a thousand instructions long, the 'flattened' code would result in a lot of execution units going idle for a long time if even one thread takes it. On a GPGPU the naive code port would be horrendous performance. You have to think of if/then branches in terms of "Will iterations within %32 of each other all branch the same?" and I don't think that's as plainly obvious as everyone else does.

Just seemed like everyone's glossing over the most relevant detail he said to shout "embarrassingly parallel!" louder.

1337JiveTurkey
Feb 17, 2005

JawnV6 posted:

So when this lands on a GPU, if anyone takes that branch then every single execution unit is going through all 5 instructions. 40% of your potential throughput is wasted because of that if/then.

If it's like predicated instructions on a CPU, I'm pretty sure that it's actually going to cost you the time to evaluate every single instruction regardless of the thread states. Otherwise it's just going to do the equivalent of a pipeline bubble. Given that the execution units can dispatch up to 5 instructions at once, it's possible that the branches can be interleaved to cost less than it otherwise would.

JawnV6
Jul 4, 2004

So hot ...
I'm really not sure what you're saying. Strictly speaking about GPU's, the 'execution units' are too dumb to control the instruction stream. There's one instruction fetch unit for every group of 32 threads. Every one of those 32 threads has to be considering the same instruction, therefore if any of them diverge on a branch you're basically issuing nops on the other 31. There's no 'interleaving' there's no bubbles, there's just some EU's working and some lying idle while the threads they're held together with work on the other path.

If everyone%32 takes the same direction on each branch this isn't an issue, every EU will be doing 'real' work on every tick.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
I'm playing around with machine learning before I start getting heavy into the network monitoring app I'm writing. What are some cool things to attempt with hidden Markov models that are more complicated than doing pattern analysis on Rock-Paper-Scissors or something?

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
Man, I wish I knew anything about processors.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


Misogynist posted:

I'm playing around with machine learning before I start getting heavy into the network monitoring app I'm writing. What are some cool things to attempt with hidden Markov models that are more complicated than doing pattern analysis on Rock-Paper-Scissors or something?

There's a pretty large literature on financial modeling with HMMs. You can easily find data and some ideas if you go digging around.

Zombywuf
Mar 29, 2008

Misogynist posted:

I'm playing around with machine learning before I start getting heavy into the network monitoring app I'm writing. What are some cool things to attempt with hidden Markov models that are more complicated than doing pattern analysis on Rock-Paper-Scissors or something?

Predict which poster will post next.

mik
Oct 16, 2003
oh
Interesting discussion on the implications of logic inside the GPU code. I can definitely cut down on the number of if/then branches that gets passed, if not eliminate them entirely, as the logic is essentially if A > B then keep computing else stop, not head down another path. I could even let it do the computation and pick out the elements I want to keep back in the host code.

Basically I need to do:

code:
if(A1>(B1*Y*D)){

  R = (A2-A1)*X + (B2-B1)*X*Y

}elseif(A1<(B1*Y*D)){{

  R = (A1-A2)*X + (B1-B2)*X*Y

}else{

  R = 0

}
...roughly 120,000,000 times. I have a 6950 which should be beefy enough to handle it. Of course I'll try it on both the GPU and CPU to find out what N iterations gives advantage to the GPU. And what optimizations I can do (mad(), etc)

mik fucked around with this message at 21:48 on Jun 21, 2011

JawnV6
Jul 4, 2004

So hot ...
I'm honestly in the dark as far as ATI's implementation goes. I was strictly speaking about CUDA's handling of diverging branches. For all I know ATI cards handle branches like a champ and I'm completely off base.

I definitely think you should learn one GPGPU flavor if only to understand the limitations and tradeoffs inherent in that choice. If the same sort of predicated execution is hampering your performance the required refactoring will be a learning experience.

Looking at that code, the only thing the if/then is determining is the signs of the operands. You could compute each term outside, then have the if/then just doing a single computation (apply signs to operands) with everything else independent of it.

So:
code:
t1 = (A1-A2)*X
t2 = (B2-B1)*X*Y
if(A1>(B1*Y*D)){
  // nothing
}elseif(A1<(B1*Y*D)){{
  t1 = -1 * t1;
  t2 = -1 * t2;
}else{
  t1 = t2 = 0;
}
R=t1 + t2;

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

ultrafilter posted:

There's a pretty large literature on financial modeling with HMMs. You can easily find data and some ideas if you go digging around.
It's interesting that you mention that, because most of the good literature on time series analysis, which is another crucial part of this monitoring project, is in the econometrics field, because quantitative trading is where most really smart math people seem to be ending up these days. So while I think this is a really good idea, I think my brain is oversaturated with that right now. :)

1337JiveTurkey
Feb 17, 2005

JawnV6 posted:

I'm really not sure what you're saying. Strictly speaking about GPU's, the 'execution units' are too dumb to control the instruction stream. There's one instruction fetch unit for every group of 32 threads. Every one of those 32 threads has to be considering the same instruction, therefore if any of them diverge on a branch you're basically issuing nops on the other 31. There's no 'interleaving' there's no bubbles, there's just some EU's working and some lying idle while the threads they're held together with work on the other path.

If everyone%32 takes the same direction on each branch this isn't an issue, every EU will be doing 'real' work on every tick.

I guess I'm probably a bit confused about the exact setup of the processors that the code is running on. From what I understand if half the threads take one path, then it halts execution of the other half, runs the first half to the point where they would converge and then starts the other half from where it left off. That's inevitably going to have some sort of overhead such as pipeline flushing.

However if it's small enough then the instructions will be predicated instead, which is what I was referring to. In that case everything maintains the same PC and is given the same instruction. However only some threads actually execute that instruction based on their predicate registers while the others do nothing for the cycle.

I was probably thinking too much of how Itanium handles predicates since it's also a predicated VLIW architecture. In that case, each instruction in the bundle can be predicated separately. So if you've got:
code:
if (foo) {
    x = x * 2;
}
else {
    x = x * 3;
}
It's perfectly fine in Itanium to do both in the same instruction. I guess it doesn't matter that much although it does show how hard it can be to assess the cost of an individual if statement in this context.

Nippashish
Nov 2, 2005

Let me see you dance!

Misogynist posted:

I'm playing around with machine learning before I start getting heavy into the network monitoring app I'm writing. What are some cool things to attempt with hidden Markov models that are more complicated than doing pattern analysis on Rock-Paper-Scissors or something?

Generative language models are fun. Grab some books off project Gutenberg to train it then run it generatively and see what comes out.

Zombywuf
Mar 29, 2008

JawnV6 posted:

So:
code:
t1 = (A1-A2)*X
t2 = (B2-B1)*X*Y
if(A1>(B1*Y*D)){
  // nothing
}elseif(A1<(B1*Y*D)){{
  t1 = -1 * t1;
  t2 = -1 * t2;
}else{
  t1 = t2 = 0;
}
R=t1 + t2;

Is there a sign function? i.e:
code:
s = sign(A1 < (B1 * Y * D));
t1 = s * (A1 - A2) * X;
t2 = s * (B2 - B1) * X * Y;
R = t1 + t2;

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Nippashish posted:

Generative language models are fun. Grab some books off project Gutenberg to train it then run it generatively and see what comes out.
Or see how many iterations it takes before it generates a piece about monkeys and typewriters.

Adbot
ADBOT LOVES YOU

JawnV6
Jul 4, 2004

So hot ...

1337JiveTurkey posted:

However if it's small enough then the instructions will be predicated instead, which is what I was referring to. In that case everything maintains the same PC and is given the same instruction. However only some threads actually execute that instruction based on their predicate registers while the others do nothing for the cycle.
Yeah this is right. I think we're on the same page wrt the underlying hardware capability, it's just odd for me to think of that as a 'pipeline bubble'.

1337JiveTurkey posted:

I was probably thinking too much of how Itanium handles predicates since it's also a predicated VLIW architecture. In that case, each instruction in the bundle can be predicated separately. So if you've got:
code:
if (foo) {
    x = x * 2;
}
else {
    x = x * 3;
}
It's perfectly fine in Itanium to do both in the same instruction. I guess it doesn't matter that much although it does show how hard it can be to assess the cost of an individual if statement in this context.
Right, that's beyond the capabilities of CUDA. Threads that have foo set are executing while everyone else in the warp is idle and vice versa.

Zombywuf posted:

Is there a sign function? i.e:
code:
s = sign(A1 < (B1 * Y * D));
t1 = s * (A1 - A2) * X;
t2 = s * (B2 - B1) * X * Y;
R = t1 + t2;
No idea. I suspect something branchless is possible, but couldn't figure it out on the spot and just pulled out the most I could.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply