Open Side Menu Go to the Top

11-24-2011 , 11:37 PM
Quote:
Originally Posted by ElPonchis
Right so bump with another question, of course dont want to be told how to do it, but more tell me why this doest work!

i have to read int's from a file and store it in a two dimensional array, i really dont understand why this dont work. After every int in this file there is a comma. It just prints out random numbers all the time..im geussing im using fscanf totally wrong here as fscanf will check the whole file before the for loop repeats? so storing integars wrong! but i been told to use fscanf.


Spoiler:
Code:
                                         

#define NO_STUDENTS 10
#define NO_MARKS 4
#include <stdio.h>



int main(char argc, char *argv[])
{
        int j = 1;
        int i = 1;
        int StudentMarks[NO_STUDENTS][NO_MARKS];
        FILE *fp;
        fp = fopen(argv[1], "r");
        for ( j = 1; j <= NO_STUDENTS; j++ )
        {
                for ( i = 1; i <= NO_MARKS; i++)
                {
                        fscanf(fp,"%d  ", &StudentMarks[j][i]);
                }
        }
        printf("%d \n", StudentMarks[4][4]);
        fclose(fp);
}
Cant tell if im being dumb and its something obv
(quoting from my thread, didnt know they had low content here)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
11-25-2011 , 12:07 AM
first thing that jumps out at me is that arrays are zero indexed in c so your loops should be like for (j=0; j< NO_STUDENTS; j++) {}.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-25-2011 , 04:50 AM
Quote:
Originally Posted by greg nice
are you trying to solve this programmatically or do you just want the website backed up locally? if the latter, and you dont want to use the program listed, just download/use wget
I actually want to have all the judgements backed up locally as text. I now download all the sites using HTTrack, then I want to go through the texts and copy all the links to the judgements and go through does links again.

It is tiresome, but I cant solve it any other way it seems.

Quote:
Originally Posted by Zurvan
HTTrack will follow links deep in to the site. I scraped a website to 3 levels of navigation (all it had) with it. Just dig through the settings, it's all in there.
I looked at all the settings, but it didnt seem obvious to me that it was possible. I'll take a look again later, but might still stick to my original plan.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-25-2011 , 01:08 PM
Quote:
Originally Posted by Neko
first thing that jumps out at me is that arrays are zero indexed in c so your loops should be like for (j=0; j< NO_STUDENTS; j++) {}.

This. I think youre going out of bounds on the print statement (NO_MARKS is 4 so you cant index into 4).
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-26-2011 , 01:06 PM
Quote:
Originally Posted by kyleb
Here's another topic no one knows anything about:

I'm writing a relatively complex markov chaining program in PHP. The markov chain itself is not computationally expensive, but the outputs it gives must be then simulated at least 1 million times per event (and there's about 40 events per day). These events should be processed in batch and be ready a few hours after data is first sent to the program.

I've already written the program and the simulator works perfectly. However, as you may surmise, it runs pretty slowly. Basically there are finite state probabilities between 0 and 1 like so:

P(A): 0.000 - 0.110
P(B): 0.111 - 0.200
P(C): 0.201 - 0.300
...
...
P(Z): 0.998 - 1.000

(It's more than 4 significant digits in the floating point number but you get the idea)

The simulator calls mt_rand() to generate the probabilities, and for each of the 40 events per day, it takes about 50 of these probabilities. So 50 * 1,000,000 individual simulated states. Fortunately: They are not dependent on one another..
At the risk of asking some stupid questions - can you elaborate a little bit more on the input and output of these simulations?

My assumptions are that the input (an event) is some state in your chain, the simulation performs 50 simulated transitions, and the output is which state you ended up in. Run this a million times and output the frequency of ending in each state. Is this what you're doing or am I way off?

I'm kicking around some ideas but I wanted to make sure I am at least in the ballpark.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-26-2011 , 01:27 PM
How big is the program Kyle? Depending on what the code is like, rewriting it in C could probably get you a factor of 50 to 100x performance.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-26-2011 , 09:39 PM
I know this is a difficult question to answer, if you have 200,000 lines of C++ MFC code, how long would it take and how much roughly do people think it would cost to convert it to work on Macs?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-26-2011 , 10:47 PM
I will answer all suggestion/questions soon! Thanks for your input. Trying to think about the questions posed.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-26-2011 , 11:27 PM
thankyou for the help and everything before...i thought i finished this program but im getting some weird digits...can somebody look at the code please? (think ive done something really stupid and prob take you 5 secs to notice it).
What the program is doimg, inputting values from a file into an array, then printing the values, and then sorting them into categories...

my code
Code:
#define NO_STUDENTS 10
#define NO_MARKS 4
#include <stdio.h>



int main(int argc, char *argv[])
{
        char * comma;
        int j,i;
        int greater70,between6069,between5059,between4049,lessthan39,didnthandin;
        int StudentMarks[NO_STUDENTS][NO_MARKS];


        FILE *fp;
        fp = fopen(argv[1], "r");
        for ( j = 0; j < NO_STUDENTS; j++ )
        {
                for ( i = 0; i < NO_MARKS; i++)
                {
                        fscanf(fp,"%d%c", &StudentMarks[j][i], &comma );
                        printf("%d,", StudentMarks[j][i]);
                        if(("%d", StudentMarks[j][i]) >= 70)
                                {
                                        greater70++;
                                }
                        else if(("%d", StudentMarks[j][i]) <= 69 && ("%d", StudentMarks[j][i]) >= 60)
                                {
                                        between6069++;
                                }
                        else if(("%d", StudentMarks[j][i]) <= 59 && ("%d", StudentMarks[j][i]) >= 50)
                                {
                                        between5059++;
                                }
                        else if(("%d", StudentMarks[j][i]) <= 49 && ("%d", StudentMarks[j][i]) >= 40)
                                {
                                        between4049++;
                                }
                        else if(("%d", StudentMarks[j][i]) <= 39 && ("%d", StudentMarks[j][i]) >= 0)
                                {
                                        lessthan39++;
                                }
                        else
                                {
                                        didnthandin++;
                                }
                }
        }
        fclose(fp);

        printf("\nThe number of marks Greater or equal to 70 was %d\n", greater70);
         printf("The number of marks between 60 and 69 was %d\n", between6069);
        printf("The number of marks between 50 and 59 was %d\n", between5059);
        printf("The number of marks between 40 and 49 was %d\n", between4049);
        printf("The number of marks less than or equal to 39 was %d\n", lessthan39);
        printf("The number of courseworks not handed in was %d\n", didnthandin);
}
the ouput at the end has gone dodgy! the first 3 are right... all of them is meant to add up to 40

Spoiler:
77,66,80,81,40,5,35,-1,51,58,62,34,0,-1,21,18,61,69,58,49,81,82,90,76,44,51,60,-1,64,63,60,66,-1,38,41,50,69,80,72,75,
The number of marks Greater or equal to 70 was 10
The number of marks between 60 and 69 was 10
The number of marks between 50 and 59 was 5
The number of marks between 40 and 49 was 4196628
The number of marks less than or equal to 39 was 32747
The number of courseworks not handed in was -1399338276


edit: when i move all the variables into seperate int's, each having there own seperate line when declaring them, it works properly. Anybody care to explain why they have to be declared seperatly?

Last edited by _dave_; 11-27-2011 at 12:06 AM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-26-2011 , 11:42 PM
Quote:
Originally Posted by ElPonchis
the ouput at the end has gone dodgy! the first 3 are right... all of them is meant to add up to 40

edit: when i move all the variables into seperate int's, each having there own seperate line when declaring them, it works properly. Anybody care to explain why they have to be declared seperatly?
What are the values of those int variables before you start incrementing them?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-26-2011 , 11:47 PM
Quote:
Originally Posted by Benholio
What are the values of those int variables before you start incrementing them?
oooooo yeh! i understand!
Why would it work for the first 3 when i havent assigned a value but it would pick a random number to start incrementing from for the last 3?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-26-2011 , 11:59 PM
Going with the theme of busted codes going way too long. I've been waiting for this answer for well over 5 minutes and it still hasn't came.

At least I know the correct answer will eventually spit out, but wow....
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-27-2011 , 12:10 AM
you don't set comma anywhere?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-27-2011 , 12:19 AM
Quote:
Originally Posted by ElPonchis
oooooo yeh! i understand!
Why would it work for the first 3 when i havent assigned a value but it would pick a random number to start incrementing from for the last 3?
When you don't initialize a variable it contains some arbitrary garbage value. Often that value will be zero but not always. This can lead to some bugs that are really hard to track because some of the time the initial value will be zero and everything will behave as expected and then you'll run it again and you'll get a totally different/unexpected result.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-27-2011 , 05:22 AM
Quote:
Originally Posted by Gullanian
I know this is a difficult question to answer, if you have 200,000 lines of C++ MFC code, how long would it take and how much roughly do people think it would cost to convert it to work on Macs?
well, what's the goal. do you want 200,000 lines of objective C or cocoa or whatever in addition to the 200,000 lines of mfc? do you want to move the whole application to a cross-platform toolkit such as Qt? if the application has a well-encapsulated gui layer, this latter step should be easy, right? /whistles innocently
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-27-2011 , 09:05 AM
Quote:
Originally Posted by sylar
kyleb, why don't you pre-generate the random numbers? or extract the processing into a separate service? 1million requests is tough, but you could batch them into 100-1k, and have the service process them in parallel?
Pre-generating the random numbers might shave off a ton of time; that's a good idea. It's easy to do, too, so I think I'll try that first.

Quote:
Originally Posted by TheIrishThug
haven't done PHP in years, so I can't help you with frameworks. But if the API you have doesn't seem to have a mechanism to return a value, there might be a way to initially pass in a reference to an array. Then when the job is done, you can access the results in the parent. If that doesn't work, you can always write to disk and read the results back in.
I think I will use this method with the pre-generation of random numbers and see if it improves performance.

Quote:
Originally Posted by Benholio
At the risk of asking some stupid questions - can you elaborate a little bit more on the input and output of these simulations?

My assumptions are that the input (an event) is some state in your chain, the simulation performs 50 simulated transitions, and the output is which state you ended up in. Run this a million times and output the frequency of ending in each state. Is this what you're doing or am I way off?

I'm kicking around some ideas but I wanted to make sure I am at least in the ballpark.
Yes, it's more or less a baseball simulator. The markov chain figures out various expectancies for the base/out states and then the pitcher vs. batter simulation is done (singles, doubles, triples, etc). Baserunning/defense is not simulated (we just apply a modifier for defense - think UZR - and baserunning - think BsR).

Simulate the number of interactions in a game to get to 27 outs (or how many ever outs we care about for derivatives of the full game) for both sides and repeat this process 1MM times.

Quote:
Originally Posted by Neko
How big is the program Kyle? Depending on what the code is like, rewriting it in C could probably get you a factor of 50 to 100x performance.
I don't know enough C/C++ or even .NET/C# to rewrite this, plus I'd need to figure out how to develop the web service in those languages too, which I have no idea how to do (plus database calls, etc).

I've successfully compiled HipHop for PHP (Facebook's source code transformer that turns PHP into C++) which helps, but it's pretty complicated stuff.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-27-2011 , 01:37 PM
I'm building a new web server virtual machine and I'm trying to build Hiphop for PHP on it. I'm running Ubuntu 11.10 (trying it out despite all the bitching) and I can install the depedencies just fine except for libcurl. I filed a Stack Overflow ticket with more detail if anyone wants to check it out here:

http://stackoverflow.com/questions/8...u-11-10-hiphop
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-27-2011 , 01:46 PM
sounds like you have a wrong (too old?) version of libcurl or maybe some of your ssl libraries. does hiphop specify which versions of these deps it wants? what is the output of dpkg -l '*curl*'? (and maybe '*ssl*')?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-27-2011 , 01:57 PM
dpkg -l '*curl*'

Code:
kyle@ubuntu:~/dev/hiphop-php/src$ dpkg -l '*curl*'
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                     Version                  Description
+++-========================-========================-================================================================
un  curl                     <none>                   (no description available)
un  gnupg-curl               <none>                   (no description available)
un  libcurl-dev              <none>                   (no description available)
un  libcurl-ssl-dev          <none>                   (no description available)
un  libcurl2                 <none>                   (no description available)
ii  libcurl3                 7.21.6-3ubuntu3          Multi-protocol file transfer library (OpenSSL)
un  libcurl3-dbg             <none>                   (no description available)
un  libcurl3-dev             <none>                   (no description available)
ii  libcurl3-gnutls          7.21.6-3ubuntu3          Multi-protocol file transfer library (GnuTLS)
un  libcurl3-openssl-dev     <none>                   (no description available)
un  libcurl4                 <none>                   (no description available)
un  libcurl4-gnutls          <none>                   (no description available)
un  libcurl4-gnutls-dev      <none>                   (no description available)
ii  libcurl4-openssl-dev     7.21.6-3ubuntu3          Development files and documentation for libcurl (OpenSSL)
ii  python-pycurl            7.19.0-4ubuntu2          Python bindings to libcurl
un  python-pycurl-dbg        <none>                   (no description available)
un  python2.3-pycurl         <none>                   (no description available)
un  python2.4-pycurl         <none>                   (no description available)
un  python2.6-pycurl         <none>                   (no description available)
un  python2.7-pycurl         <none>                   (no description available)
dpkg -l '*ssl*'

Code:
kyle@ubuntu:~/dev/hiphop-php/src$ dpkg -l '*ssl*'
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                     Version                  Description
+++-========================-========================-================================================================
un  docbook-dsssl            <none>                   (no description available)
un  libcurl-ssl-dev          <none>                   (no description available)
un  libcurl3-openssl-dev     <none>                   (no description available)
ii  libcurl4-openssl-dev     7.21.6-3ubuntu3          Development files and documentation for libcurl (OpenSSL)
un  libengine-pkcs11-openssl <none>                   (no description available)
ii  libssl-dev               1.0.0e-2ubuntu4          SSL development libraries, header files and documentation
ii  libssl-doc               1.0.0e-2ubuntu4          SSL development documentation documentation
ii  libssl1.0.0              1.0.0e-2ubuntu4          SSL shared libraries
ii  openssl                  1.0.0e-2ubuntu4          Secure Socket Layer (SSL) binary and related cryptographic tools
un  openssl-blacklist        <none>                   (no description available)
un  openssl-doc              <none>                   (no description available)
ii  python-openssl           0.12-1ubuntu1            Python wrapper around the OpenSSL library
un  python-openssl-dbg       <none>                   (no description available)
un  python-openssl-doc       <none>                   (no description available)
un  python2.6-openssl        <none>                   (no description available)
un  python2.7-openssl        <none>                   (no description available)
ii  ssl-cert                 1.0.28                   simple debconf wrapper for OpenSSL
un  wget-ssl                 <none>                   (no description available)
The Hiphop libcurl make/build instructions:

Quote:
wget http://curl.haxx.se/download/curl-7.21.2.tar.gz
tar -xvzf curl-7.21.2.tar.gz
cd curl-7.21.2
cp ../hiphop-php/src/third_party/libcurl.fb-changes.diff .
patch -p1 < libcurl.fb-changes.diff
./configure --prefix=$CMAKE_PREFIX_PATH
make
make install
cd ..
Guide I am following:

https://github.com/facebook/hiphop-p...n-ubuntu-10.10

Relevant Github pull request:

https://github.com/facebook/hiphop-php/pull/322
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-27-2011 , 02:03 PM
Here are the errors when I just try and cmake . Hiphop and ignoring libcurl problems:

Code:
CMake Error at CMake/HPHPFindLibs.cmake:90 (message):
  Custom libcurl is required with the HipHop patch
Call Stack (most recent call first):
  CMake/HPHPSetup.cmake:46 (include)
  src/CMakeLists.txt:18 (include)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-27-2011 , 02:05 PM
my guess is that your build process isn't configured to find the correct libcurl (the one you're attempting to patch as opposed to the system library).

is CMAKE_PREFIX_PATH defined in your environment? that looks suspicious.

you also might try installing the libcurl3-dev package.

football time! gl.

Last edited by tyler_cracker; 11-27-2011 at 02:06 PM. Reason: "as opposed to" means "don't write the same thing twice, noob"
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-27-2011 , 09:31 PM
not sure if people read books but all apress books will be $15 ebook format starting at midnight eastern

some of the books in their alpha program look good
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-27-2011 , 09:32 PM
wow nice
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-28-2011 , 12:04 AM
Quote:
Originally Posted by tyler_cracker
my guess is that your build process isn't configured to find the correct libcurl (the one you're attempting to patch as opposed to the system library).

is CMAKE_PREFIX_PATH defined in your environment? that looks suspicious.

you also might try installing the libcurl3-dev package.

football time! gl.
I accepted this answer:

http://stackoverflow.com/questions/8...289430#8289430
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-28-2011 , 06:31 PM
BTW HipHop is really great, I've used it in the past and I plan on using HPHP served pages for some heavy processing in the future, definitely worth checking out.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

      
m