i am trying to apply constraints on array such that the element present in array which are greater than 1 and 4, are completely divisible by that element. and such elements are stored in another array. How can I do that in GPU programming using GPLK library and JUMP library.
I’m not sure I understand your problem, can you explain in more detail what you are trying to do? And why does it have to be on a GPU?
thank you for reply , In normal julia program (CPU runnable) by applying constraint we get possible combinations of results for example x + y >3 give me possible combinations of x and y which addition should be less than 3 using GPLK and JuMP package . so i want to apply that condition on GPU program so how can i use it . I want to do it on GPU program due to performance issue
I have one CuArray in GPU program so i want those elements in that CuArray which are greater than 1 and that element completely divisible by 4 by using GPLK package if I got that solution then I can able to convert our CPU runnable julia program into GPU runnable
I don’t think it matters much to JuMP whether your arrays live on the CPU or on the GPU, because the underlying solvers (like GLPK) are written in a different language anyway, so they won’t use the same objects. If you’re facing performance issues, you are probably better off re-examining your modeling choices or switching solvers (GLPK is notoriously inefficient, try HiGHS instead).
EDIT: I asked the experts, and some solvers do support a GPU backend, like SCS. But most linear solvers don’t.
As for your actual constraint, can you give me a mathematical formulation of the problem?
I just want to know that Can we use GLPK library in GPU programming? If yes then how?
this is my constraint below
for i in 1:length(array)
if (array[i] >= 2 && 4 % array[i] == 0)
@constraint(model, x[i] == 1)
end
end
For GLPK specifically I don’t think it’s possible. But I’m out of my depth here so I’m calling @odow
My best guess is, all it takes is to put all your problem parameters in CuArray
s instead of Array
s and let dispatch do the rest, but I’m not sure how to deal with variables because the documentation on variable containers does not mention GPU arrays.
thank you very much sir I will try that solution ,
and I also want to ask one question that how to know is my program is running on GPU.
For a simple, full-Julia program, I would say you need to check that all of the arrays you create still live on the GPU. Check out the CUDA.jl documentation for more details.
But since JuMP is full of metaprogramming and calls solvers in other languages, the task seems much harder and I’m afraid I cannot help you.
Okay ,Thank you sir
I’m not @odow, nor do I play him on television
From what you have written here, x[i]
will take the (binary?) value 1 only when array[i] == 4
. If this is what you meant then the following might work:
for i in 1:length(array)
@constraint(model, array[i] <= 4*x[i])
@constraint(model, 4*x[i] <= array[i])
end
This assumes that 0 <= array[i] <= 4
. But maybe that’s not what you meant…
@healyp thank you for reply ,can we use GLPK package in GPU program of Julia .if yes then How?
Sorry, I don’t have any useful ideas on how to do this.
No, you cannot use GLPK on a GPU.
I really don’t think so, at least not for the program resolution.
GLPK is a solver engine written in C++ for linear (and mixed integers) problems.
“GPU programming” in Julia refers to execute Julia code in the GPU but I really don’t think it is possible to run external calls to C interface in the GPU.
At the very best (and I highly doubt so) it could be possible to construct the model from the nice math-friendly format that is given to JuMP to the matrix format that the GLPK solver expects, but not the solving itself.
From your example perhaps this is what you want to do… run the code of the if
block you posted above in the GPU… in that case the solver engine to be used (GLPK) is ininfluent… by the way… I notice that you use “GPLK”, are you referring to “GLPK” (GNU Linear Programming Kit), right ?
Thank you sir,
Is there any alternative way to GLPK to apply constraint in GPU program of julia
thank you sir , can you provide me alternative way to apply constraint on expression in GPU program of julia
As others have pointed out, why do you want this? A GPU will not make your code faster when using JuMP.
If your code is too slow, please start a new thread with a reproducible example of what you’re trying to achieve.