Zorrito
Separately, outside main()
Huh. Maybe share your code and someone can look it over.
Alignant
int var = 5; void somefunc() { // some code } int main() { var++; return 0; } Are you doing it like this?
_̸̡͝͝This
More like this :
_̸̡͝͝This
int black = 5; void foo() { black = 0; } int main(int argc, char const *argv[]) { foo(); return 0; }
olli
this works as well, globals such as your variable black can be accessed form everywhere
Alignant
I think you made a typo somewhere, this is valid
Alignant
From everywhere in this file :D
_̸̡͝͝This
Yes, I'm checking with an online compiler and it works
olli
From everywhere in this file :D
From everywhere in the same compilation unit
_̸̡͝͝This
Must be a problem with my compiler then...
olli
that's one of the problems with globals
Alignant
_̸̡͝͝This
Okay... I found the issue
Alignant
that's one of the problems with globals
If you need it in only 2 function, why don't you pass it by a ref?
_̸̡͝͝This
The variables must be defined BEFORE you define the function
_̸̡͝͝This
I though the compiler started compiling the global variables and then the functions lol
olli
If you need it in only 2 function, why don't you pass it by a ref?
Actually you should - there was a discussion about using globals earlier in this chat
Onur
Do I need to include any header to use size_t?
Alignant
True :D No you don't by the way
Onur
why don't you just try it?
it gives error when I want to take a template argument with size_t
Onur
but it just compiles when I define a variable with size_t
Zorrito
I though the compiler started compiling the global variables and then the functions lol
Naw, you have to do everything in order. If you don't declare a variable before you use it, the compiler will pretend the variable doesn't exist.
_̸̡͝͝This
Thank you guys for helping me so much !
Roxifλsz 🇱🇹
/warn bitcoin ad
Anonymous
int i, sum; int * ptr = malloc(5 * sizeof(int)); for (i = 0; i< 5; i++) *(ptr + i) = i; How come the value always zero ?
Jussi
Which value?
Anonymous
Which value?
ptr[0] = 0; ptr[1] = 0; ptr[2] = 0; ptr[3] = 0; ptr[4] = 0;
Jussi
How do you print them out?
Anonymous
How do you print them out?
sry my bad. wrong printing way.
Jussi
:)
Dominic
So what's the difference between C ++ and python
_̸̡͝͝This
Hi, uhm, is there any reason why doing an assignment with a pointer inside
_̸̡͝͝This
Okay, nevermind 😅
Dominic
Kk
Alignant
So what's the difference between C ++ and python
They are so different, but nevertheless, they are both the most hated languages
Jussi
Why is c++ hated?
Jussi
So what's the difference between C ++ and python
The main difference is that for python you run the source code itself. There is a python interpreter that does the actual job, your code just instructs that interpreter. In C(++), you need to COMPILE your code so it becomes machine code that will be directly executed. There is no need for interpreter for C languages, but you need to compile your code into an executable before you can run it
Anonymous
Hi everyone
Anonymous
I had learned basic programming in my first year of college and then things went wrong in life for two years. I have dropped out but still want to learn programming.
Anonymous
Returning to learn again after almost three years. Forgive me if I ask very simple and basic questions at times.
Anonymous
Thank you. I look forward to learning from you all.
Onur
Is it possible to make a variable inside a class only to visible from its namespace?
Onur
Like internal keyword in c#
Zorrito
I know this may be a noob question, but I'm working with a library (QPULib) which functions by compiling and running kernels, and I'm having problems with making it working correctly. So, a kernel accesses shared arrays through pointers, but it doesn't seem to like when I use the same array as an input and an output. Is the language just set up such that it's impossible to do that? Do I really need to create a secondary array just to appease the C++ gods, or is there a way around it?
Anonymous
Are you trying to do something like this?
Anonymous
myfunction(char output[], char input[]){ copy(output, input) } ... char output[] = "Hola, como estas"; myfunction(output, output)
Zorrito
myfunction(char output[], char input[]){ copy(output, input) } ... char output[] = "Hola, como estas"; myfunction(output, output)
Like this: void kernel(Ptr<Float> p, Ptr<Float> q){ Float array_name_1 = *p; Float array_name_2 = *q; array_name_1 = array_name_1 + array_name_2; *p = array_name_1; }
Zorrito
Like this: void kernel(Ptr<Float> p, Ptr<Float> q){ Float array_name_1 = *p; Float array_name_2 = *q; array_name_1 = array_name_1 + array_name_2; *p = array_name_1; }
Then the main function would be like this: int main(){ auto k = compile(kernel); SharedArray<float> array_name_1(array_size), array_name_2(array_size); k.setNumQPUs(2); k(&array_name_1, &array_name_2); }
Zorrito
You are using something like CUDA?
It's using QPULib, a library for programming a RPi's GPU. Idk how similar it is to CUDA, but I think they're different.
Zorrito
https://github.com/mn416/QPULib
Zorrito
https://github.com/mn416/QPULib
Here's the library. It includes example code that you can play around with.
Anonymous
#include <stdio.h> void copy(float p[], float q[], int n) { int i; for(i = 0; i < n; i++){ p[i] = p[i]+q[i]; } } int main() { int i, n = 7; // n is len of a float a[] = {0.1, .2, .3, .4, .5, .6, .7}; copy(a, a, n); for (i = 0; i < n; i++) printf("%f\n", a[i]); return 0; }
Anonymous
Example in c
Zorrito
void gcd(Ptr<Int> p, Ptr<Int> q, Ptr<Int> r) { Int a = *p; Int b = *q; While (any(a != b)) Where (a > b) a = a-b; End Where (a < b) b = b-a; End End *r = a; } int main() { // Construct kernel auto k = compile(gcd); // Allocate and initialise arrays shared between ARM and GPU SharedArray<int> a(16), b(16), r(16); srand(0); for (int i = 0; i < 16; i++) { a[i] = 100 + (rand() % 100); b[i] = 100 + (rand() % 100); } // Invoke the kernel and display the result k(&a, &b, &r); for (int i = 0; i < 16; i++) printf("gcd(%i, %i) = %i\n", a[i], b[i], r[i]); return 0; }
Anonymous
?
Anonymous
void kernel(Ptr<Float> p, Ptr<Float> q){ *p = *p + *q }
Or you have to iterate over p and q elements?
Zorrito
Or you have to iterate over p and q elements?
I have to iterate it over all elements (in my case, it's 384 elements in each array). But the kernel is supposed to be able to do the iteration automatically, by design. The library is set up so that it does the same instruction in batches of 16 (times the number of QPUs used in the RPi's GPU.
Anonymous
I am doing nazi things with CUDA right now xd
Sanjay
😘
Anonymous
Sanjay
what do you need
I wanted to Import stock data to text file from XML, Json what is the easiest way ?
Zorrito
Yeah, is like CUDA
Hmmm maybe I should do a little more research into CUDA and see how it compares. I might get some questions answered that way.
Sanjay
Sanjay