These are chat archives for uwhpsc-2016/uwhpsc-2016

5th
May 2016
mvelegar
@mvelegar
May 05 2016 00:56
@mostberg1 correct.
gadamico
@gadamico
May 05 2016 00:56
Hi, Meghana. Are you there?
mvelegar
@mvelegar
May 05 2016 00:56
@shinwookang sure, just open a private chat thread
@gadamico yea
@gadamico yes*
gadamico
@gadamico
May 05 2016 00:57
I'm having some sort of compiler issue with the library.so file. I posted two issues to my private repo.
That is, two "issues"
Would you mind taking a look?
mvelegar
@mvelegar
May 05 2016 00:57
I am looking at it right now
gadamico
@gadamico
May 05 2016 00:57
Thank you.
I guess I'm successfully "making" the file, but when I run the python test script I don't get test results back!
WalesJ
@WalesJ
May 05 2016 00:59
@mvelegar I would like to speak to you in a private chat to talk about my code, please.
Chris Kang
@shinwookang
May 05 2016 01:01
HI @mvelegar I've sent you a private message. thank you.
gadamico
@gadamico
May 05 2016 01:11
Still there, Meghana?
mvelegar
@mvelegar
May 05 2016 01:13
Yes, I am still here and still trying to figure out why make test is not working for you. Unravelling the issue to it's source taking time!
gadamico
@gadamico
May 05 2016 01:13
:smile:
I appreciate your efforts
xuzhuofei
@xuzhuofei
May 05 2016 01:17
Hi, Meghana @mvelegar , I wonder if it's possible for us to get a sense what the performance for gauss_seidel should look like? I know we can use time_gauss_seidel to get execution time, but I guess it is really hard to tell whether it is a fast or slow one. It would be a helpful information for me to decide whether I need to modify my implementation for gauss_seidel. Thank you!
gadamico
@gadamico
May 05 2016 01:24
Is it possible that something got lost in the git pulling and pushing? I remember that at one point, when Chris posted some bug fix (to the wrappers.py file, perhaps? I forget), I had to do a merge even though Chris posted an announcement saying that that shouldn't be necessary....
mvelegar
@mvelegar
May 05 2016 01:25
@gadamico you have a typo in line 89 of solvers.c where you are calling solve_lower_trianglar instead of solve_lower_triangular.
gadamico
@gadamico
May 05 2016 01:25
!
Could that make all the difference?
mvelegar
@mvelegar
May 05 2016 01:26
<hysterical laughter> yes. especially with the current wrapper design
gadamico
@gadamico
May 05 2016 01:27
I just ran 'make test' again. I got some warning messages--and a FAIL, which I'll have to check on--but the tests ran! Hooray!
Thanks so much, Meghana. I don't know if I'd ever have found that.
Chris Kang
@shinwookang
May 05 2016 01:32
hey @gadamico ! you're in the facebook group correct?
WalesJ
@WalesJ
May 05 2016 01:32
There's a facebook for this class?
Chris Kang
@shinwookang
May 05 2016 01:33
no, just general AMATH people I think
gadamico
@gadamico
May 05 2016 01:33
Yes, I am.
gadamico
@gadamico
May 05 2016 01:43
So I'm getting warning messages to the effect that certain of my pointers may be uninitialized. Is there something more I should be doing to initialize them besides (declaring them and then) using a for loop to set their referents' entries to zero?
Maybe I should say something about what they're pointing to, but I'm thinking of them as arrays rather than pointers....
xuzhuofei
@xuzhuofei
May 05 2016 01:50
Still here? @mvelegar
mvelegar
@mvelegar
May 05 2016 01:55
Yes sorry @xuzhuofei flurry of questions
gadamico
@gadamico
May 05 2016 01:55
Partly my fault!
I'll plan to ask Chris about this tomorrow.
WalesJ
@WalesJ
May 05 2016 01:56
Me too
mladenze
@mladenze
May 05 2016 01:57
HW2, Question 3: "What are the memory requirements as a function of n, the system size?" So, are we also supposed to account for the arrays that are passed to the function?
gadamico
@gadamico
May 05 2016 01:58
I have to go anyway, so I'm signing out. Thanks so much for the sharp eye, Meghana!
mvelegar
@mvelegar
May 05 2016 01:59
@xuzhuofei all I can say is Gauss Seidel should give you better performance than Jacobi, and you should see this for really large problems. For smaller problems Jacobi does better. If you see this with your implementation, you are golden. Also, make sure you have been "smart" about reusing data that you have instead of performing a mat*vec operation
@mladenze you should be thinking of your "total" memory usage, you have to account for all the data structures you have created and used (should be dependent on the problem size n)
OH are officially over, am trying to finish up issues on Private chats now
xuzhuofei
@xuzhuofei
May 05 2016 02:05
@mvelegar Thank you for the last minute answer! I need to think over that advice!
mladenze
@mladenze
May 05 2016 02:06
@mvelegar Thank you.
Saket Potluri
@saketpotluri
May 05 2016 02:38
@mvelegar Just to confirm, both GS and Jacobi should start the initial guess of the solution to Ax = b to be a vector of zeros
dawong94
@dawong94
May 05 2016 02:39
Am i the only one feel Jacobi and GS is so hard to code in this hw??
nishalad95
@nishalad95
May 05 2016 02:40
no you're not the only one! :P
Saket Potluri
@saketpotluri
May 05 2016 02:40
Yup quite a challenge since you have define temporary vectors and matrices to hold intermediate calculations
dawong94
@dawong94
May 05 2016 02:42
I was wandering if i misunderstood the question since I defined so many temporary matrices and vectors
but it seems like not only me doing this way
lol
mladenze
@mladenze
May 05 2016 03:21
@dawong94 @nishalad95 @saketpotluri @dawong94 I actually miss MATLAB.
dawong94
@dawong94
May 05 2016 04:19
@mladenze and Java
nishalad95
@nishalad95
May 05 2016 16:34
I was wondering whether anyone can help, in my code I need one array (out) to point to another array (x0), but I keep getting the syntax wrong. Can anyone shed some light on this?
Hugh Krogh-Freeman
@hughkf
May 05 2016 16:37
If you just want out to point to x0, then it would be "out = x0;"
nishalad95
@nishalad95
May 05 2016 16:50
ok i'll try that, thanks!
but what would mean that out and x0 now stored the same values?
nishalad95
@nishalad95
May 05 2016 17:02
this syntax doesn't actually work :/
I need to get them both to store the same values, x0 is currently empty and out is full, so I thought why not have x0 point to out so that they both contain the same values, instead of doing a for loop, but i can't get the syntax right
Chris Kang
@shinwookang
May 05 2016 17:10
Hey @cswiercz , when you have a chance today (during office hours), would it be possible to help debug my method in private chat?
Hugh Krogh-Freeman
@hughkf
May 05 2016 17:42
@nishalad95 You said "point". If you want x0 and out to be clones, i.e. to store the same values, you need to use memcpy from string.h
Does anyone know how large a problem size we should expect our code to handle? I get a core dump for really large N.
@mvelegar For the number of iterations from Gauss-Seidel, as compared with Jacobi, I get a ratio that differs from 1/2 by as much as 0.09. Is this within the margin of error, or do I need to fix my code?
jdstead
@jdstead
May 05 2016 18:46
I am having major issues getting my code to run from the source file. I have written workable stand alone programs for almost all of the functions in linalg.c and the solvers.c, but i cannot get them to behave in src.c. i think the thing that is tripping me up primarily is the argument pass. I keep getting errors like: "passing argument 2 of ‘mat_add’ from incompatible pointer type" or "expected ‘double ’ but argument is of type ‘double ()3’" I am having fundamental issues understanding the pass of pointers. Am I alone on this?
natwall27
@natwall27
May 05 2016 18:47
You are not alone @jdstead. I am having similar issues.
nishalad95
@nishalad95
May 05 2016 18:49
Thank you! i'll try that
jdstead
@jdstead
May 05 2016 18:50
i am able to get vec_add and vec_sub to pass a 1D array. but matrices choke on it every time
nishalad95
@nishalad95
May 05 2016 18:50
@hughkf my understanding of point was like a linked list in java, but I guess that's not the case here
natwall27
@natwall27
May 05 2016 18:54
This message was deleted
#include "linalg.h"
#include "solvers.h"

// matrices L, U, and A are all long arrays of size NxN
// b is an array of length N

void solve_lower_triangular(double* out, double* L, double* b, int N)
{
    for(int i=0; i<N; ++i)
    {
        out[i] = b[i];
        for(int j=1; j<(i+1);++j)
        {
            out[i] -= L[i*N+i-j]*out[i-j];
        }
        out[i] = out[i]/L[i*N+i];
    }
}

void solve_upper_triangular(double* out, double* U, double* b, int N)
{
    for(int i=1; i< (N-1); ++i)
    {
        out[N-i] = b[N-i];
        for(int j=1; j<i; ++j)
        {
            out[N-i] -= U[(N-i)*N+N-(i-j)]*out[N-(i-j)];
        }
        out[N-i] = out[N-i]/U[(N-i)*N+N-i];
    }
}

int jacobi(double* out, double* A, double* b, int N, double epsilon)
{
    double x_init[N]; // Need to have initial guess

    double* T = A; // Create Matrix without diagonal entries

    for(int i = 0; i < N; ++i)
    {
        T[i*N+i] = 0;
    }

    double Ax[N];
    mat_vec(Ax,A,x_init,N,N);

    double difference[N];
    vec_sub(difference,Ax,b,N);

    double norm_diff;
    norm_diff = vec_norm(difference,N);

    double x_next[N];
    x_next = x_init;

    int count = 0;

    while(norm_diff > epsilon)
    {
        double Tx[N];
        mat_vec(Tx,T, x_next,N,N);

        double Sx[N];
        vec_sub(Sx,b,Tx,N);

        for(int j = 0; j < N; ++j)
        {
            x_next[j] = Sx[j] / A[j*N + j];
        }

        double Ax[N];
        mat_vec(Ax,A,x_next,N,N);

        double difference[N];
        vec_sub(difference, Ax, b,N);

        double norm_diff;
        norm_diff = vec_norm(difference,N);

        count += 1;
    }

  return 0;
}

int gauss_seidel(double* out, double* A, double* b, int N, double epsilon)
{
    double x_init[N]; // Need to have initial guess

    double Ax[N];
    mat_vec(Ax,A,x_init,N,N);

    double difference[N];
    vec_sub(difference, Ax, b, N);

    double norm_diff;
    norm_diff = vec_norm(difference,N);

    double x_next[N];
    x_next = x_init;

    double L[N*N]; // Extract lower-triangle

    for(int i=0; i < N; i++)
    {
        for(int j=0; j<i; ++j)
        {
            L[i*N + j] = A[i*N + j];
        }
    }

    double S[N*N];
    mat_add(S,A, -1*L,N,N);

    int count = 0;

    while(norm_diff > epsilon)
    {

        double Lx[N];
        mat_vec(Lx,L, x_next,N,N);

        double Sx[N];
        vec_sub(Sx,b, Lx,N);

        solve_upper_triangular(x_next, S, Sx, N);

        double Ax[N]; 
        mat_vec(Ax,A,x_next,N,N);

        double difference[N];
        vec_sub(difference, Ax, b,N);

        double norm_diff;
        norm_diff = vec_norm(difference,N);

        count += 1;
    }
  return 0;
}
Oh no!
thank is suppose to go into my private chat.
does anyone know how to delete it?
Chris Kang
@shinwookang
May 05 2016 18:58
next to your chat
click the "..."
and delete
@natwall27
natwall27
@natwall27
May 05 2016 18:59
thanks!
I see hide and leave
Got it. Thank you, @shinwookang !
Chris Swierczewski
@cswiercz
May 05 2016 19:03

Office Hours - Begin

I am already working with a student right now so please be patient while I try to answer everyone's questions.
nishalad95
@nishalad95
May 05 2016 19:05
can we use memcpy if we wanted to clone to arrays to be the same temporarily? Also - How can we use the time gauss_seidel method, I'm slightly confused on your docstring because it contains some import statements so I wasn't sure if we need to use them and take out the docstring?
Hugh Krogh-Freeman
@hughkf
May 05 2016 19:09
@cswiercz When I use a size of 10, my solve_upper_triangular and solve_lower_triangular tests pass. But when I bump it up to 20, I start getting failures. Am I right in thinking there is something wrong with my code?
djg25
@djg25
May 05 2016 19:12
@cswiercz when you're available can I ask you a quick question in private chat? I think there's a small issue in the Jupyter notebook when I try to count the number of iterations for the 5-diagonal matrix
Chris Swierczewski
@cswiercz
May 05 2016 19:13
Yikes! Be with you all in one minute. Addressing another student right now.
gadamico
@gadamico
May 05 2016 19:15
Hi, Chris. Question for you when you have a moment: When I (re-) compile the library I get warning messages about possibly having uninitialized pointers. In my code I have lines like: double *x0; for (int i=0; i<N; ++i) {x0[i] = 0;}. Is there something I'm missing about pointer initialization?
jdstead
@jdstead
May 05 2016 19:16
Also, Chris, when you are done with all of that, I have basic pointer question for you
Chris Swierczewski
@cswiercz
May 05 2016 19:18
@nishalad95 Take a look at the documentation for timeit.timeit. The string s represent a bunch of code you want to execute before timing the first argument to timeit. It uses a completely separate namespace so things that you've defined within test_homework2.py but not within the string do not exist from the timer's perspective.
nishalad95
@nishalad95
May 05 2016 19:19
ok thank you! I'll have a look
Chris Swierczewski
@cswiercz
May 05 2016 19:19
@hughkf There are some issues threads where @quantheory correctly points out that triangular solvers are "unstable" w.r.t. random input. That might be the reason. Try adding something large "$O(N)$" to each of the diagonal elements of A before solving.
@djg25 Just a moment. I'll finish writing up public responses first.
Hugh Krogh-Freeman
@hughkf
May 05 2016 19:22
@cswiercz Thanks! I'll try that.
Chris Swierczewski
@cswiercz
May 05 2016 19:22

@gadamico You initialized a variable of type double* but you never have it point to anything. This is called an "uninitialized pointer". Instead, you should set x0 equal to the address of a heap-allocated array, such as

double* x0;
x0 = (double*) malloc( ... );

or let x0 point to a stack-allocated arrray:

double x0[N];  // x0 is of type double*
@jdstead What is your question?
gadamico
@gadamico
May 05 2016 19:22
Ahhhh. Thanks!
Chris Kang
@shinwookang
May 05 2016 19:22
Hi chris, if you have a chance I sent you a private chat
jdstead
@jdstead
May 05 2016 19:23
i am having a hard time passing a 2d array into the mat_add and mat_mat functions. i can get them to work standalone, but passing a 2d array always gives me errors
gadamico
@gadamico
May 05 2016 19:23
Oh, so writing a variable with the '[]' afterward is equivalent to using the '*'?
I was wondering about the code I saw with the square brackets. This would probably also explain why, when I tried things like double * x0[N] I was creating variables of type double**!
jdstead
@jdstead
May 05 2016 19:25
oh so the question i guess, is are we supposed to be deconstructing the matrices into one long array, and then reconstruct it in the function?
Chris Swierczewski
@cswiercz
May 05 2016 19:28

@jdstead You may have come across some codes online where people create "2D arrays" like so:

double my_mat[5][5];

This is not how we are storing arrays in this homework nor in this class. The above is of type double** whereas we are storing matrices as "long" arrays. In the above case, we would insteast use

double my_may[25];

and iterpret the first five elements as "row 0", the next five as "row 1". Etc. I mention this in the README.md.

anders34
@anders34
May 05 2016 19:29
When I run make test I get this error:
Chris Swierczewski
@cswiercz
May 05 2016 19:29
The input to all of the linalg.c functions are assumed to be 1d arrays representing matrices. I've used this notation throughout lecture.
anders34
@anders34
May 05 2016 19:29
OSError: You need to compile your homework library using 'make'.
Makefile:28: recipe for target 'test' failed
make: * [test] Error 1
any idea why?
gadamico
@gadamico
May 05 2016 19:30
I got that error for a while, myself, @anders34. Mine turned out to be the result of a very minor typo!
So it could be lots of things.
Hugh Krogh-Freeman
@hughkf
May 05 2016 19:30
@cswiercz What maximum problem size will hw2 be tested against?
Chris Swierczewski
@cswiercz
May 05 2016 19:30

@gadamico The notation

double* x0[N];

means "create an array of length N where each element is of type double*". It's not what you think it is.

anders34
@anders34
May 05 2016 19:30
do you think it's an error in the test_homework2.py file?
Chris Swierczewski
@cswiercz
May 05 2016 19:31
@hughkf N < 10 for tests, N \approx ....50-100ish for GS timing.
Hugh Krogh-Freeman
@hughkf
May 05 2016 19:31
thx!
gadamico
@gadamico
May 05 2016 19:32
Oh, I see. Boy, I need to go back and look at some C rules. Thanks.
jhyearsley
@jhyearsley
May 05 2016 19:33
So in general, when a function takes in an arbitrary input N we should allocate space in the heap yeah?
I'm wondering what would happen functionally if not (i.e. how would the OS deal with something like that... crash and burn?... stack overflow..? etc)
Chris Swierczewski
@cswiercz
May 05 2016 19:35
By the way everyone: there are about right people asking questions right now. I'm slowly working through them.
jdstead
@jdstead
May 05 2016 19:35
yes i did read that. and yeah i have been initializing the matrices as M[i][j] or something along those lines. thanks for saying it one more time...probably won't be the last
nicksmithc102
@nicksmithc102
May 05 2016 19:35
He meant 8!
or eight
Hugh Krogh-Freeman
@hughkf
May 05 2016 19:44
@cswiercz we expect the ratio of Gauss-Seidel and Jacobi iterations to be 1/2. Is 0.59 for size > 100 close enough?
Chris Swierczewski
@cswiercz
May 05 2016 19:46
From my experiments with the 5-diag system I think the ratio is around there.
gadamico
@gadamico
May 05 2016 19:46
Bye and thanks again, Chris. Very helpful.
Hugh Krogh-Freeman
@hughkf
May 05 2016 19:47
Great. Thanks @cswiercz
anders34
@anders34
May 05 2016 19:50
Would you mind taking a look at the changes I've pushed to GitHub to see why, when I run make test, I'm getting this error:
OSError: You need to compile your homework library using 'make'.
Makefile:28: recipe for target 'test' failed
make: * [test] Error 1
Chris Swierczewski
@cswiercz
May 05 2016 19:56
@gadamico No worries!
@hughkf Of course!
@anders34 Taking a look now.
Was that all in the compile message?
anders34
@anders34
May 05 2016 19:58
Umm...I guess maybe I don't know what the compile message is. This is everything that comes up with I run make test:
~/homework2-anders34$ make test
gcc -lm --shared src/linalg.o src/solvers.o -o lib/libhomework2.so
python test_homework2.py
Traceback (most recent call last):
File "test_homework2.py", line 10, in <module>
from homework2 import (
File "/projects/59d28b86-013a-4f59-ae59-9294cb033cef/homework2-anders34/homework2/init.py", line 1, in <module>
from wrappers import
File "/projects/59d28b86-013a-4f59-ae59-9294cb033cef/homework2-anders34/homework2/wrappers.py", line 24, in <module>
raise OSError("You need to compile your homework library using 'make'.")
OSError: You need to compile your homework library using 'make'.
Makefile:28: recipe for target 'test' failed
make: **
[test] Error 1
I don't know why it didn't copy and paste, but above where it says "from wrappers import" there should be a * at the end of that statement
Chris Swierczewski
@cswiercz
May 05 2016 20:07
(Next time can you encapsulate your paste with a "```" at the top and bottom? [without the double-quotes] It will be easier to read.
e.g.
~/homework2-anders34$ make test
gcc -lm --shared src/linalg.o src/solvers.o -o lib/libhomework2.so
python test_homework2.py
Traceback (most recent call last):
File "test_homework2.py", line 10, in <module>
from homework2 import (
File "/projects/59d28b86-013a-4f59-ae59-9294cb033cef/homework2-anders34/homework2/init.py", line 1, in <module>
from wrappers import 
File "/projects/59d28b86-013a-4f59-ae59-9294cb033cef/homework2-anders34/homework2/wrappers.py", line 24, in <module>
raise OSError("You need to compile your homework library using 'make'.")
OSError: You need to compile your homework library using 'make'.
Makefile:28: recipe for target 'test' failed
make: ** [test] Error 1
hmmm....let's see here.
What is the output of make lib?
anders34
@anders34
May 05 2016 20:10
gcc -lm --shared src/linalg.o src/solvers.o -o lib/libhomework2.so
Chris Swierczewski
@cswiercz
May 05 2016 20:10
That's it?
anders34
@anders34
May 05 2016 20:10
yeah...should it not be?
Chris Swierczewski
@cswiercz
May 05 2016 20:10
It should be.
Did you ever edit wrappers.py?
anders34
@anders34
May 05 2016 20:11
certainly not intentionally! although I suppose it's possible that happened
Chris Swierczewski
@cswiercz
May 05 2016 20:16
Hmmm...
Let me take a look at your test_homework2.py code.
Actually, I'm going to open your SMC project.
I'm not sure if you can see what I'm typing in your Terminal.term.
anders34
@anders34
May 05 2016 20:19
yeah, I can
Chris Swierczewski
@cswiercz
May 05 2016 20:19
I wonder if the empty line here is a problem....
Man...what happened.
I'll switch to using the SMC file browser.
nishalad95
@nishalad95
May 05 2016 20:22
Hey Chris I'm just having trouble understanding one thing in the timeit
in your docstring for the the method, you say n : int The size of the test system to solve, but I'm not sure what n actually is?
Chris Swierczewski
@cswiercz
May 05 2016 20:23
@anders34 Hmmm.....
I'm going to restart your SMC project. Something is fishy.
anders34
@anders34
May 05 2016 20:24
okay
Chris Swierczewski
@cswiercz
May 05 2016 20:24
Before I do: you are sure that you didn't modify Makefile or anything in homework2, yes?
anders34
@anders34
May 05 2016 20:25
I am 99% sure
Chris Swierczewski
@cswiercz
May 05 2016 20:25
:)
I'm going to try to verbatim copy the directory into the wrapper.
Okay. So it's not failing on finding your library.
I'm going to start an iPython session and see if there are any problems there...
anders34
@anders34
May 05 2016 20:28
okay, whatever you've got to do! I appreciate the help!
Chris Swierczewski
@cswiercz
May 05 2016 20:28

Office Hours - End

Sorry, @nishalad95 but I have to go. I'm just wrapping up @anders34 question.
nishalad95
@nishalad95
May 05 2016 20:29
no worries - i think i got it to work!
Chris Swierczewski
@cswiercz
May 05 2016 20:30
What if I create a new terminal....
Hey! I think I'm finally onto something.
(i'm working in "TestTerm.term)
anders34
@anders34
May 05 2016 20:32
Yeah, I just found that
Chris Swierczewski
@cswiercz
May 05 2016 20:33
Something is wrong in the library, either in linalg or solvers. You're trying to use something called zeros but it doesn't exist.
I'm goign to open your solvers.c
anders34
@anders34
May 05 2016 20:34
If I had to guess, it's probably in solvers, because I'm pretty sure I got linalg to work before this happened
Chris Swierczewski
@cswiercz
May 05 2016 20:34
HA! Found it.
Lines 45-47 of solvers.c
There's no such thing as a function called zeros
The reason why a compile error isn't thrown is because the library looks for such a function at runtime.
anders34
@anders34
May 05 2016 20:35
Wow...all that just because there's no such thing as zeros!
Chris Swierczewski
@cswiercz
May 05 2016 20:35
Okay. I'm definitely late for a meeting now.

Office Hours - End (For Real) Gotta Go

anders34
@anders34
May 05 2016 20:35
Oh my gosh...I'm so sorry, but thank you so much for your help!
Chris Swierczewski
@cswiercz
May 05 2016 20:36
No worries;
nishalad95
@nishalad95
May 05 2016 20:48
does anyone know what n is in def time_gauss_seidel(n, number=1): for the timing of the gauss_seidel method?
is it the size of your matrix?
/ system to solve?
Marisa Preciado
@Marisa67
May 05 2016 21:54
nishalad95, n is the size of the matrix you are going to time. You can change the size in line 305 of test_homework2.py. Chris wrote a 2**8 there but you can test any size you want.
nishalad95
@nishalad95
May 05 2016 21:55
thank you!