Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple sessions doesn't seem to work on Windows #151

Open
rcnlee opened this issue Nov 24, 2018 · 7 comments
Open

Multiple sessions doesn't seem to work on Windows #151

rcnlee opened this issue Nov 24, 2018 · 7 comments

Comments

@rcnlee
Copy link

rcnlee commented Nov 24, 2018

using MATLAB
s1 = MSession()
s2 = MSession()
put_variable(s1, :y, 1)
put_variable(s2, :y, 2)
jvalue(get_mvariable(s1, :y)  #output1
jvalue(get_mvariable(s2, :y)  #output2

I'm expecting output1=1 and output2=2. Works on mac.
However, it doesn't seem to work on Windows, where I get output1=output2=2.

Anyone know what's going on? I see there's some special handling of persistent sessions for Windows, but it looks like the code should work.

@rcnlee
Copy link
Author

rcnlee commented Nov 24, 2018

This thread seems to suggest that the fix should be opening the dummy persistent session with engOpenSingleUse. However, in the code, I don't see that being called. It looks like it is just calling MSession(0) which uses engOpen. On Windows, this leads to a shared global context.

@rcnlee
Copy link
Author

rcnlee commented Nov 25, 2018

All sessions that use engOpen share a global context. My interest is actually in multiple parallel processes, so it seems like I need engOpenSingleUse for all my MSessions.

@musm
Copy link
Collaborator

musm commented Nov 26, 2018

I'm not sure what is a good solution in this case.

@rcnlee
Copy link
Author

rcnlee commented Nov 26, 2018

I got it to work for parallel processes using engOpenSingleUse for all sessions. However, startup is very very slow. For large jobs, the parallelization still outweighs the startup cost.
In thinking about it though, only the global variables are shared. Function calls are still local. So as long as the parallelism only relies on function calls, there is no need to change anything.

@rcnlee
Copy link
Author

rcnlee commented Dec 2, 2018

Maybe just let the user decide by adding a keyword argument to the constructor of the session: MSession(; single_use::Bool=false) and default it to the current behavior.

@Myrddinlefou
Copy link

I use julia on windows and I have the same problem.

Did a solution is developped ?

@rcnlee
Copy link
Author

rcnlee commented Oct 1, 2019

I eventually did fine a workaround, although I don't have the exact code with me to check. I believe the workaround was to add a keyword argument single_use to MSession which defaults to false. Then do an if-else on the ccall to eng_open. If single_use is true, call eng_open_single_use, otherwise call eng_open. You might need to adjust the exact arguments in the ccall. Then when you go to use it, start the first sessionwith single_use=false and the other ones with single_use=true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants