# Can we use GLPK library in GPU programming?

**URL:** https://discourse.julialang.org/t/can-we-use-glpk-library-in-gpu-programming/101697
**Category:** GPU
**Tags:** jump, gpu
**Created:** [July 17, 2023, 2:59pm UTC](https://discourse.julialang.org/t/can-we-use-glpk-library-in-gpu-programming/101697 "2023-07-17T14:59:58Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![Jayesh\_Patil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jayesh_patil/32/51605_2.png) [@Jayesh\_Patil](https://discourse.julialang.org/u/Jayesh_Patil)
#### Post date: [July 17, 2023, 2:59pm UTC](https://discourse.julialang.org/t/can-we-use-glpk-library-in-gpu-programming/101697/1 "2023-07-17T14:59:58Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [July 17, 2023, 4:14pm UTC](https://discourse.julialang.org/t/can-we-use-glpk-library-in-gpu-programming/101697/2 "2023-07-17T16:14:10Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Jayesh\_Patil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jayesh_patil/32/51605_2.png) [@Jayesh\_Patil](https://discourse.julialang.org/u/Jayesh_Patil)
#### Post date: [July 18, 2023, 6:26am UTC](https://discourse.julialang.org/t/can-we-use-glpk-library-in-gpu-programming/101697/3 "2023-07-18T06:26:34Z")

</div>

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

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [July 18, 2023, 6:30am UTC](https://discourse.julialang.org/t/can-we-use-glpk-library-in-gpu-programming/101697/4 "2023-07-18T06:30:14Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Jayesh\_Patil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jayesh_patil/32/51605_2.png) [@Jayesh\_Patil](https://discourse.julialang.org/u/Jayesh_Patil)
#### Post date: [July 18, 2023, 6:39am UTC](https://discourse.julialang.org/t/can-we-use-glpk-library-in-gpu-programming/101697/5 "2023-07-18T06:39:25Z")

</div>

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

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [July 18, 2023, 6:41am UTC](https://discourse.julialang.org/t/can-we-use-glpk-library-in-gpu-programming/101697/6 "2023-07-18T06:41:23Z")

</div>

> [@Jayesh\_Patil](#):
>
> I just want to know that Can we use GLPK library in GPU programming? If yes then how?

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](https://jump.dev/JuMP.jl/stable/manual/variables/#Variable-containers) does not mention GPU arrays.

---

<div class="post-metadata">

### Author: ![Jayesh\_Patil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jayesh_patil/32/51605_2.png) [@Jayesh\_Patil](https://discourse.julialang.org/u/Jayesh_Patil)
#### Post date: [July 18, 2023, 6:47am UTC](https://discourse.julialang.org/t/can-we-use-glpk-library-in-gpu-programming/101697/7 "2023-07-18T06:47:34Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [July 18, 2023, 6:49am UTC](https://discourse.julialang.org/t/can-we-use-glpk-library-in-gpu-programming/101697/8 "2023-07-18T06:49:59Z")

</div>

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](https://github.com/JuliaGPU/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.

---

<div class="post-metadata">

### Author: ![Jayesh\_Patil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jayesh_patil/32/51605_2.png) [@Jayesh\_Patil](https://discourse.julialang.org/u/Jayesh_Patil)
#### Post date: [July 18, 2023, 7:04am UTC](https://discourse.julialang.org/t/can-we-use-glpk-library-in-gpu-programming/101697/9 "2023-07-18T07:04:26Z")

</div>

Okay ,Thank you sir

---

<div class="post-metadata">

### Author: ![healyp](https://avatars.discourse-cdn.com/v4/letter/h/67e7ee/32.png) [@healyp](https://discourse.julialang.org/u/healyp)
#### Post date: [July 18, 2023, 8:14am UTC](https://discourse.julialang.org/t/can-we-use-glpk-library-in-gpu-programming/101697/10 "2023-07-18T08:14:31Z")

</div>

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:

```julia
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…

---

<div class="post-metadata">

### Author: ![Jayesh\_Patil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jayesh_patil/32/51605_2.png) [@Jayesh\_Patil](https://discourse.julialang.org/u/Jayesh_Patil)
#### Post date: [July 18, 2023, 9:14am UTC](https://discourse.julialang.org/t/can-we-use-glpk-library-in-gpu-programming/101697/11 "2023-07-18T09:14:22Z")

</div>

@healyp thank you for reply ,can we use GLPK package in GPU program of Julia .if yes then How?

---

<div class="post-metadata">

### Author: ![healyp](https://avatars.discourse-cdn.com/v4/letter/h/67e7ee/32.png) [@healyp](https://discourse.julialang.org/u/healyp)
#### Post date: [July 18, 2023, 10:32am UTC](https://discourse.julialang.org/t/can-we-use-glpk-library-in-gpu-programming/101697/12 "2023-07-18T10:32:00Z")

</div>

Sorry, I don’t have any useful ideas on how to do this.

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [July 18, 2023, 12:43pm UTC](https://discourse.julialang.org/t/can-we-use-glpk-library-in-gpu-programming/101697/13 "2023-07-18T12:43:23Z")

</div>

No, you cannot use GLPK on a GPU.

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [July 18, 2023, 12:54pm UTC](https://discourse.julialang.org/t/can-we-use-glpk-library-in-gpu-programming/101697/14 "2023-07-18T12:54:24Z")

</div>

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](https://en.wikipedia.org/wiki/GNU_Linear_Programming_Kit)), right ?

---

<div class="post-metadata">

### Author: ![Jayesh\_Patil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jayesh_patil/32/51605_2.png) [@Jayesh\_Patil](https://discourse.julialang.org/u/Jayesh_Patil)
#### Post date: [July 18, 2023, 1:44pm UTC](https://discourse.julialang.org/t/can-we-use-glpk-library-in-gpu-programming/101697/15 "2023-07-18T13:44:54Z")

</div>

Thank you sir,  
Is there any alternative way to GLPK to apply constraint in GPU program of julia

---

<div class="post-metadata">

### Author: ![Jayesh\_Patil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jayesh_patil/32/51605_2.png) [@Jayesh\_Patil](https://discourse.julialang.org/u/Jayesh_Patil)
#### Post date: [July 18, 2023, 1:48pm UTC](https://discourse.julialang.org/t/can-we-use-glpk-library-in-gpu-programming/101697/16 "2023-07-18T13:48:56Z")

</div>

thank you sir , can you provide me alternative way to apply constraint on expression in GPU program of julia

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [July 18, 2023, 1:51pm UTC](https://discourse.julialang.org/t/can-we-use-glpk-library-in-gpu-programming/101697/17 "2023-07-18T13:51:38Z")

</div>

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.
