Execute fortran subroutine through parallel python impossible to execute Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceHow to iterate through two lists in parallel?Parallel Python: Passing a function written in another module to 'submit'How to convert Pytorch autograd.Variable to Numpy?An error occurred while starting the karnel - Anaconda pythonimport surprise throws ContextualVersionConflict error in python3import pandas error in SpyderCan't use eager execution in Tensorflow 1.5 on windows7 machineI am getting lookup table not initialized error when looking up the tableParallel: Import a python file from sibling folderException in thread QueueManagerThread - scikit-learn
Classification of bundles, Postnikov towers, obstruction theory, local coefficients
When is phishing education going too far?
What do you call the holes in a flute?
What items from the Roman-age tech-level could be used to deter all creatures from entering a small area?
What was the last x86 CPU that did not have the x87 floating-point unit built in?
Cold is to Refrigerator as warm is to?
Geometric mean and geometric standard deviation
If A makes B more likely then B makes A more likely"
I'm having difficulty getting my players to do stuff in a sandbox campaign
How to rotate it perfectly?
Is there a documented rationale why the House Ways and Means chairman can demand tax info?
Single author papers against my advisor's will?
Active filter with series inductor and resistor - do these exist?
Direct Experience of Meditation
What's the point in a preamp?
Do working physicists consider Newtonian mechanics to be "falsified"?
Stopping real property loss from eroding embankment
How do I automatically answer y in bash script?
Stars Make Stars
What is the order of Mitzvot in Rambam's Sefer Hamitzvot?
Problem when applying foreach loop
How to market an anarchic city as a tourism spot to people living in civilized areas?
Are my PIs rude or am I just being too sensitive?
Working around an AWS network ACL rule limit
Execute fortran subroutine through parallel python impossible to execute
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceHow to iterate through two lists in parallel?Parallel Python: Passing a function written in another module to 'submit'How to convert Pytorch autograd.Variable to Numpy?An error occurred while starting the karnel - Anaconda pythonimport surprise throws ContextualVersionConflict error in python3import pandas error in SpyderCan't use eager execution in Tensorflow 1.5 on windows7 machineI am getting lookup table not initialized error when looking up the tableParallel: Import a python file from sibling folderException in thread QueueManagerThread - scikit-learn
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am trying to execute a fortran subroutine in python 2.7 using parallel python (PP package). But when I execute it using pp.server().submit(...) nothing happens. I might have implemented it wrong, I have used the numpy.f2py.compile()
as explained here. Could someone please tell me if this is correct? And if not, what should I change?
Just to mention that the code is almost surely correct given that it is taken from a doctorate thesis (code, paper).
The subroutine implemented in a python 2.7 module called "design_operation" is:
import numpy.f2py
fsource = '''
subroutine matrix_op(grid_x,grid_t,eval_grid,pas,K,L,M,C)
COMPLEX :: i=(0.0,1.0)
INTEGER , intent(in) :: K,L,M
REAL , intent(in) :: pas
INTEGER :: u,v,w
REAL , dimension(1:M) , intent(in) :: grid_x
REAL , dimension(1:K) , intent(in) :: grid_t
REAL , dimension(1:L) , intent(in) :: eval_grid
COMPLEX, dimension(1:L,1:M) , intent(out) :: C
do u=1,L
do v=1,M
do w=1,K
C(u,v) = C(u,v) - i*pas*grid_t(w)*grid_x(v)*exp(-i*grid_t(w)*grid_x(v)*eval_grid(u))
end do
end do
end do
end subroutine matrix_op
'''
numpy.f2py.compile(fsource, modulename='design_operation', verbose=0)
Then, I call it this way:
job_server.submit(func=list_append,
args=(grid_x, grid_t, sub_eval[k,:], pas_f,),
modules=('numpy as np','design_operation as fdp',)
which is actually in a loop and should be executed in:
job_server = pp.Server()
thread_number = job_server.get_ncpus()
...some unimportant code ...
jobs = []
for k in range(thread_number):
jobs.append(job_server.submit(func=list_append,
args=(grid_x, grid_t, sub_eval[k,:], pas_f,),
modules=('numpy as np','design_operation as fdp',)))
for i,job in enumerate(jobs):
if i == 0:
dM = job()
else:
dM = np.concatenate((dM, job()))
job_server.destroy()
return dM
I always get the following error: zero-dimensiona arrays cannot be concatenated.
Therefore I suppose that the error comes from the incorrect execution of the tasks, but perhaps am I mistaking.
The stack error is:
An error has occured during the function execution
Traceback (most recent call last):
File "C:ProgramDataAnaconda3envsprojectlibsite-packagesppworker.py", line 90, in run
__result = __f(*__args)
File "<string>", line 2, in list_append
AttributeError: 'module' object has no attribute 'matrix_op'
An error has occured during the function execution
Traceback (most recent call last):
File "C:ProgramDataAnaconda3envsprojectlibsite-packagesppworker.py", line 90, in run
__result = __f(*__args)
File "<string>", line 2, in list_append
AttributeError: 'module' object has no attribute 'matrix_op'
Traceback (most recent call last):
File "<ipython-input-89-6cb5b50fd813>", line 5, in <module>
dM = np.concatenate((dM, job()))#
ValueError: zero-dimensional arrays cannot be concatenated
PS: I supposed there is some unnecessary code and therefore I didn't include it for more clarity + the arguments of func= list_append are correct.
python numpy parallel-processing fortran parallel-python
add a comment |
I am trying to execute a fortran subroutine in python 2.7 using parallel python (PP package). But when I execute it using pp.server().submit(...) nothing happens. I might have implemented it wrong, I have used the numpy.f2py.compile()
as explained here. Could someone please tell me if this is correct? And if not, what should I change?
Just to mention that the code is almost surely correct given that it is taken from a doctorate thesis (code, paper).
The subroutine implemented in a python 2.7 module called "design_operation" is:
import numpy.f2py
fsource = '''
subroutine matrix_op(grid_x,grid_t,eval_grid,pas,K,L,M,C)
COMPLEX :: i=(0.0,1.0)
INTEGER , intent(in) :: K,L,M
REAL , intent(in) :: pas
INTEGER :: u,v,w
REAL , dimension(1:M) , intent(in) :: grid_x
REAL , dimension(1:K) , intent(in) :: grid_t
REAL , dimension(1:L) , intent(in) :: eval_grid
COMPLEX, dimension(1:L,1:M) , intent(out) :: C
do u=1,L
do v=1,M
do w=1,K
C(u,v) = C(u,v) - i*pas*grid_t(w)*grid_x(v)*exp(-i*grid_t(w)*grid_x(v)*eval_grid(u))
end do
end do
end do
end subroutine matrix_op
'''
numpy.f2py.compile(fsource, modulename='design_operation', verbose=0)
Then, I call it this way:
job_server.submit(func=list_append,
args=(grid_x, grid_t, sub_eval[k,:], pas_f,),
modules=('numpy as np','design_operation as fdp',)
which is actually in a loop and should be executed in:
job_server = pp.Server()
thread_number = job_server.get_ncpus()
...some unimportant code ...
jobs = []
for k in range(thread_number):
jobs.append(job_server.submit(func=list_append,
args=(grid_x, grid_t, sub_eval[k,:], pas_f,),
modules=('numpy as np','design_operation as fdp',)))
for i,job in enumerate(jobs):
if i == 0:
dM = job()
else:
dM = np.concatenate((dM, job()))
job_server.destroy()
return dM
I always get the following error: zero-dimensiona arrays cannot be concatenated.
Therefore I suppose that the error comes from the incorrect execution of the tasks, but perhaps am I mistaking.
The stack error is:
An error has occured during the function execution
Traceback (most recent call last):
File "C:ProgramDataAnaconda3envsprojectlibsite-packagesppworker.py", line 90, in run
__result = __f(*__args)
File "<string>", line 2, in list_append
AttributeError: 'module' object has no attribute 'matrix_op'
An error has occured during the function execution
Traceback (most recent call last):
File "C:ProgramDataAnaconda3envsprojectlibsite-packagesppworker.py", line 90, in run
__result = __f(*__args)
File "<string>", line 2, in list_append
AttributeError: 'module' object has no attribute 'matrix_op'
Traceback (most recent call last):
File "<ipython-input-89-6cb5b50fd813>", line 5, in <module>
dM = np.concatenate((dM, job()))#
ValueError: zero-dimensional arrays cannot be concatenated
PS: I supposed there is some unnecessary code and therefore I didn't include it for more clarity + the arguments of func= list_append are correct.
python numpy parallel-processing fortran parallel-python
Can you edit in the full stack trace of the error?
– ruohola
Mar 8 at 14:58
I'm not familiar with the parallel python package, but somewhat with F2PY. You get an error message that "'module' object has no attribute 'matrix_op'", that could indicate that the function is not being loaded. You import the F2PY module design_operation as fdp, but you do not show where thefdp.matrix_op
is being used? How islist_append
defined in your code?
– jbdv
Mar 11 at 8:15
add a comment |
I am trying to execute a fortran subroutine in python 2.7 using parallel python (PP package). But when I execute it using pp.server().submit(...) nothing happens. I might have implemented it wrong, I have used the numpy.f2py.compile()
as explained here. Could someone please tell me if this is correct? And if not, what should I change?
Just to mention that the code is almost surely correct given that it is taken from a doctorate thesis (code, paper).
The subroutine implemented in a python 2.7 module called "design_operation" is:
import numpy.f2py
fsource = '''
subroutine matrix_op(grid_x,grid_t,eval_grid,pas,K,L,M,C)
COMPLEX :: i=(0.0,1.0)
INTEGER , intent(in) :: K,L,M
REAL , intent(in) :: pas
INTEGER :: u,v,w
REAL , dimension(1:M) , intent(in) :: grid_x
REAL , dimension(1:K) , intent(in) :: grid_t
REAL , dimension(1:L) , intent(in) :: eval_grid
COMPLEX, dimension(1:L,1:M) , intent(out) :: C
do u=1,L
do v=1,M
do w=1,K
C(u,v) = C(u,v) - i*pas*grid_t(w)*grid_x(v)*exp(-i*grid_t(w)*grid_x(v)*eval_grid(u))
end do
end do
end do
end subroutine matrix_op
'''
numpy.f2py.compile(fsource, modulename='design_operation', verbose=0)
Then, I call it this way:
job_server.submit(func=list_append,
args=(grid_x, grid_t, sub_eval[k,:], pas_f,),
modules=('numpy as np','design_operation as fdp',)
which is actually in a loop and should be executed in:
job_server = pp.Server()
thread_number = job_server.get_ncpus()
...some unimportant code ...
jobs = []
for k in range(thread_number):
jobs.append(job_server.submit(func=list_append,
args=(grid_x, grid_t, sub_eval[k,:], pas_f,),
modules=('numpy as np','design_operation as fdp',)))
for i,job in enumerate(jobs):
if i == 0:
dM = job()
else:
dM = np.concatenate((dM, job()))
job_server.destroy()
return dM
I always get the following error: zero-dimensiona arrays cannot be concatenated.
Therefore I suppose that the error comes from the incorrect execution of the tasks, but perhaps am I mistaking.
The stack error is:
An error has occured during the function execution
Traceback (most recent call last):
File "C:ProgramDataAnaconda3envsprojectlibsite-packagesppworker.py", line 90, in run
__result = __f(*__args)
File "<string>", line 2, in list_append
AttributeError: 'module' object has no attribute 'matrix_op'
An error has occured during the function execution
Traceback (most recent call last):
File "C:ProgramDataAnaconda3envsprojectlibsite-packagesppworker.py", line 90, in run
__result = __f(*__args)
File "<string>", line 2, in list_append
AttributeError: 'module' object has no attribute 'matrix_op'
Traceback (most recent call last):
File "<ipython-input-89-6cb5b50fd813>", line 5, in <module>
dM = np.concatenate((dM, job()))#
ValueError: zero-dimensional arrays cannot be concatenated
PS: I supposed there is some unnecessary code and therefore I didn't include it for more clarity + the arguments of func= list_append are correct.
python numpy parallel-processing fortran parallel-python
I am trying to execute a fortran subroutine in python 2.7 using parallel python (PP package). But when I execute it using pp.server().submit(...) nothing happens. I might have implemented it wrong, I have used the numpy.f2py.compile()
as explained here. Could someone please tell me if this is correct? And if not, what should I change?
Just to mention that the code is almost surely correct given that it is taken from a doctorate thesis (code, paper).
The subroutine implemented in a python 2.7 module called "design_operation" is:
import numpy.f2py
fsource = '''
subroutine matrix_op(grid_x,grid_t,eval_grid,pas,K,L,M,C)
COMPLEX :: i=(0.0,1.0)
INTEGER , intent(in) :: K,L,M
REAL , intent(in) :: pas
INTEGER :: u,v,w
REAL , dimension(1:M) , intent(in) :: grid_x
REAL , dimension(1:K) , intent(in) :: grid_t
REAL , dimension(1:L) , intent(in) :: eval_grid
COMPLEX, dimension(1:L,1:M) , intent(out) :: C
do u=1,L
do v=1,M
do w=1,K
C(u,v) = C(u,v) - i*pas*grid_t(w)*grid_x(v)*exp(-i*grid_t(w)*grid_x(v)*eval_grid(u))
end do
end do
end do
end subroutine matrix_op
'''
numpy.f2py.compile(fsource, modulename='design_operation', verbose=0)
Then, I call it this way:
job_server.submit(func=list_append,
args=(grid_x, grid_t, sub_eval[k,:], pas_f,),
modules=('numpy as np','design_operation as fdp',)
which is actually in a loop and should be executed in:
job_server = pp.Server()
thread_number = job_server.get_ncpus()
...some unimportant code ...
jobs = []
for k in range(thread_number):
jobs.append(job_server.submit(func=list_append,
args=(grid_x, grid_t, sub_eval[k,:], pas_f,),
modules=('numpy as np','design_operation as fdp',)))
for i,job in enumerate(jobs):
if i == 0:
dM = job()
else:
dM = np.concatenate((dM, job()))
job_server.destroy()
return dM
I always get the following error: zero-dimensiona arrays cannot be concatenated.
Therefore I suppose that the error comes from the incorrect execution of the tasks, but perhaps am I mistaking.
The stack error is:
An error has occured during the function execution
Traceback (most recent call last):
File "C:ProgramDataAnaconda3envsprojectlibsite-packagesppworker.py", line 90, in run
__result = __f(*__args)
File "<string>", line 2, in list_append
AttributeError: 'module' object has no attribute 'matrix_op'
An error has occured during the function execution
Traceback (most recent call last):
File "C:ProgramDataAnaconda3envsprojectlibsite-packagesppworker.py", line 90, in run
__result = __f(*__args)
File "<string>", line 2, in list_append
AttributeError: 'module' object has no attribute 'matrix_op'
Traceback (most recent call last):
File "<ipython-input-89-6cb5b50fd813>", line 5, in <module>
dM = np.concatenate((dM, job()))#
ValueError: zero-dimensional arrays cannot be concatenated
PS: I supposed there is some unnecessary code and therefore I didn't include it for more clarity + the arguments of func= list_append are correct.
python numpy parallel-processing fortran parallel-python
python numpy parallel-processing fortran parallel-python
edited Mar 8 at 15:20
Joachim Bsh
asked Mar 8 at 14:54
Joachim BshJoachim Bsh
295
295
Can you edit in the full stack trace of the error?
– ruohola
Mar 8 at 14:58
I'm not familiar with the parallel python package, but somewhat with F2PY. You get an error message that "'module' object has no attribute 'matrix_op'", that could indicate that the function is not being loaded. You import the F2PY module design_operation as fdp, but you do not show where thefdp.matrix_op
is being used? How islist_append
defined in your code?
– jbdv
Mar 11 at 8:15
add a comment |
Can you edit in the full stack trace of the error?
– ruohola
Mar 8 at 14:58
I'm not familiar with the parallel python package, but somewhat with F2PY. You get an error message that "'module' object has no attribute 'matrix_op'", that could indicate that the function is not being loaded. You import the F2PY module design_operation as fdp, but you do not show where thefdp.matrix_op
is being used? How islist_append
defined in your code?
– jbdv
Mar 11 at 8:15
Can you edit in the full stack trace of the error?
– ruohola
Mar 8 at 14:58
Can you edit in the full stack trace of the error?
– ruohola
Mar 8 at 14:58
I'm not familiar with the parallel python package, but somewhat with F2PY. You get an error message that "'module' object has no attribute 'matrix_op'", that could indicate that the function is not being loaded. You import the F2PY module design_operation as fdp, but you do not show where the
fdp.matrix_op
is being used? How is list_append
defined in your code?– jbdv
Mar 11 at 8:15
I'm not familiar with the parallel python package, but somewhat with F2PY. You get an error message that "'module' object has no attribute 'matrix_op'", that could indicate that the function is not being loaded. You import the F2PY module design_operation as fdp, but you do not show where the
fdp.matrix_op
is being used? How is list_append
defined in your code?– jbdv
Mar 11 at 8:15
add a comment |
1 Answer
1
active
oldest
votes
I notice your code doesn't seem to pass the K, L, M
and C
variables to the Fortran routine. However, K, L, M
are used to dimension some arrays and are also used as loop counters. It's quite possible that these values are set to a default value of 0
by the compiler, or maybe more likely as None
by Python itself. That would explain your error message `ValueError: zero-dimensional arrays cannot be concatenated'.
F2PY creates wrappers so that a Fortran subroutine can be called like a Python function (i.e. the intent(out) argumentC
becomes the return value of the function), and dimensions for automatic arrays do not need to be passed explicitly, see this example in the documentation. So I don't believe that is the problem in this case.
– jbdv
Mar 11 at 8:10
@jbdv That surpises me a bit based on my reading of the docs here (see 'intent', especially 'in', 'out', and 'hide'). Not to say that things don't 'work out' in some cases even without doing so. I'd have to experiment to know more.
– Matt P
Mar 11 at 13:11
As I read that,C
which isintent(out)
in Fortran, the F2PY intent out and hence hide implies that "The argument is considered as a return variable" and "The argument is removed from the list of required or optional arguments", so when called from Python,C
should not be passed to the function, but is the function's return value.
– jbdv
Mar 11 at 13:39
While the arguments defining array dimensionsK
,L
andM
are Fortranintent(in)
and will get the F2PY attributes intent in and optional, so that they can, but don't have to, be passed to the wrapped function (but are inferred from and checked against the passed array argumentsgrid_t
,eval_grid
andgrid_x
). I may very well be wrong, but I believe this is not what's causing the OP's problems
– jbdv
Mar 11 at 13:43
@jbdv RegardingC
, I believe we are in agreement - particularly sinceC
is the onlyintent(out)
variable thenhide
is implied. However, it seems to me that even the example you linked illustrates howintent(in)
array dims must be handled explicitly to avoid issues (in that example, the interface defines how the array length is to be handled, which allows it to be optional). That's not done in the OP's code. Aside: By now, I think I could have just run an experiment, but I haven't :)
– Matt P
Mar 11 at 13:49
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55065728%2fexecute-fortran-subroutine-through-parallel-python-impossible-to-execute%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I notice your code doesn't seem to pass the K, L, M
and C
variables to the Fortran routine. However, K, L, M
are used to dimension some arrays and are also used as loop counters. It's quite possible that these values are set to a default value of 0
by the compiler, or maybe more likely as None
by Python itself. That would explain your error message `ValueError: zero-dimensional arrays cannot be concatenated'.
F2PY creates wrappers so that a Fortran subroutine can be called like a Python function (i.e. the intent(out) argumentC
becomes the return value of the function), and dimensions for automatic arrays do not need to be passed explicitly, see this example in the documentation. So I don't believe that is the problem in this case.
– jbdv
Mar 11 at 8:10
@jbdv That surpises me a bit based on my reading of the docs here (see 'intent', especially 'in', 'out', and 'hide'). Not to say that things don't 'work out' in some cases even without doing so. I'd have to experiment to know more.
– Matt P
Mar 11 at 13:11
As I read that,C
which isintent(out)
in Fortran, the F2PY intent out and hence hide implies that "The argument is considered as a return variable" and "The argument is removed from the list of required or optional arguments", so when called from Python,C
should not be passed to the function, but is the function's return value.
– jbdv
Mar 11 at 13:39
While the arguments defining array dimensionsK
,L
andM
are Fortranintent(in)
and will get the F2PY attributes intent in and optional, so that they can, but don't have to, be passed to the wrapped function (but are inferred from and checked against the passed array argumentsgrid_t
,eval_grid
andgrid_x
). I may very well be wrong, but I believe this is not what's causing the OP's problems
– jbdv
Mar 11 at 13:43
@jbdv RegardingC
, I believe we are in agreement - particularly sinceC
is the onlyintent(out)
variable thenhide
is implied. However, it seems to me that even the example you linked illustrates howintent(in)
array dims must be handled explicitly to avoid issues (in that example, the interface defines how the array length is to be handled, which allows it to be optional). That's not done in the OP's code. Aside: By now, I think I could have just run an experiment, but I haven't :)
– Matt P
Mar 11 at 13:49
|
show 1 more comment
I notice your code doesn't seem to pass the K, L, M
and C
variables to the Fortran routine. However, K, L, M
are used to dimension some arrays and are also used as loop counters. It's quite possible that these values are set to a default value of 0
by the compiler, or maybe more likely as None
by Python itself. That would explain your error message `ValueError: zero-dimensional arrays cannot be concatenated'.
F2PY creates wrappers so that a Fortran subroutine can be called like a Python function (i.e. the intent(out) argumentC
becomes the return value of the function), and dimensions for automatic arrays do not need to be passed explicitly, see this example in the documentation. So I don't believe that is the problem in this case.
– jbdv
Mar 11 at 8:10
@jbdv That surpises me a bit based on my reading of the docs here (see 'intent', especially 'in', 'out', and 'hide'). Not to say that things don't 'work out' in some cases even without doing so. I'd have to experiment to know more.
– Matt P
Mar 11 at 13:11
As I read that,C
which isintent(out)
in Fortran, the F2PY intent out and hence hide implies that "The argument is considered as a return variable" and "The argument is removed from the list of required or optional arguments", so when called from Python,C
should not be passed to the function, but is the function's return value.
– jbdv
Mar 11 at 13:39
While the arguments defining array dimensionsK
,L
andM
are Fortranintent(in)
and will get the F2PY attributes intent in and optional, so that they can, but don't have to, be passed to the wrapped function (but are inferred from and checked against the passed array argumentsgrid_t
,eval_grid
andgrid_x
). I may very well be wrong, but I believe this is not what's causing the OP's problems
– jbdv
Mar 11 at 13:43
@jbdv RegardingC
, I believe we are in agreement - particularly sinceC
is the onlyintent(out)
variable thenhide
is implied. However, it seems to me that even the example you linked illustrates howintent(in)
array dims must be handled explicitly to avoid issues (in that example, the interface defines how the array length is to be handled, which allows it to be optional). That's not done in the OP's code. Aside: By now, I think I could have just run an experiment, but I haven't :)
– Matt P
Mar 11 at 13:49
|
show 1 more comment
I notice your code doesn't seem to pass the K, L, M
and C
variables to the Fortran routine. However, K, L, M
are used to dimension some arrays and are also used as loop counters. It's quite possible that these values are set to a default value of 0
by the compiler, or maybe more likely as None
by Python itself. That would explain your error message `ValueError: zero-dimensional arrays cannot be concatenated'.
I notice your code doesn't seem to pass the K, L, M
and C
variables to the Fortran routine. However, K, L, M
are used to dimension some arrays and are also used as loop counters. It's quite possible that these values are set to a default value of 0
by the compiler, or maybe more likely as None
by Python itself. That would explain your error message `ValueError: zero-dimensional arrays cannot be concatenated'.
answered Mar 9 at 17:59
Matt PMatt P
1,5791620
1,5791620
F2PY creates wrappers so that a Fortran subroutine can be called like a Python function (i.e. the intent(out) argumentC
becomes the return value of the function), and dimensions for automatic arrays do not need to be passed explicitly, see this example in the documentation. So I don't believe that is the problem in this case.
– jbdv
Mar 11 at 8:10
@jbdv That surpises me a bit based on my reading of the docs here (see 'intent', especially 'in', 'out', and 'hide'). Not to say that things don't 'work out' in some cases even without doing so. I'd have to experiment to know more.
– Matt P
Mar 11 at 13:11
As I read that,C
which isintent(out)
in Fortran, the F2PY intent out and hence hide implies that "The argument is considered as a return variable" and "The argument is removed from the list of required or optional arguments", so when called from Python,C
should not be passed to the function, but is the function's return value.
– jbdv
Mar 11 at 13:39
While the arguments defining array dimensionsK
,L
andM
are Fortranintent(in)
and will get the F2PY attributes intent in and optional, so that they can, but don't have to, be passed to the wrapped function (but are inferred from and checked against the passed array argumentsgrid_t
,eval_grid
andgrid_x
). I may very well be wrong, but I believe this is not what's causing the OP's problems
– jbdv
Mar 11 at 13:43
@jbdv RegardingC
, I believe we are in agreement - particularly sinceC
is the onlyintent(out)
variable thenhide
is implied. However, it seems to me that even the example you linked illustrates howintent(in)
array dims must be handled explicitly to avoid issues (in that example, the interface defines how the array length is to be handled, which allows it to be optional). That's not done in the OP's code. Aside: By now, I think I could have just run an experiment, but I haven't :)
– Matt P
Mar 11 at 13:49
|
show 1 more comment
F2PY creates wrappers so that a Fortran subroutine can be called like a Python function (i.e. the intent(out) argumentC
becomes the return value of the function), and dimensions for automatic arrays do not need to be passed explicitly, see this example in the documentation. So I don't believe that is the problem in this case.
– jbdv
Mar 11 at 8:10
@jbdv That surpises me a bit based on my reading of the docs here (see 'intent', especially 'in', 'out', and 'hide'). Not to say that things don't 'work out' in some cases even without doing so. I'd have to experiment to know more.
– Matt P
Mar 11 at 13:11
As I read that,C
which isintent(out)
in Fortran, the F2PY intent out and hence hide implies that "The argument is considered as a return variable" and "The argument is removed from the list of required or optional arguments", so when called from Python,C
should not be passed to the function, but is the function's return value.
– jbdv
Mar 11 at 13:39
While the arguments defining array dimensionsK
,L
andM
are Fortranintent(in)
and will get the F2PY attributes intent in and optional, so that they can, but don't have to, be passed to the wrapped function (but are inferred from and checked against the passed array argumentsgrid_t
,eval_grid
andgrid_x
). I may very well be wrong, but I believe this is not what's causing the OP's problems
– jbdv
Mar 11 at 13:43
@jbdv RegardingC
, I believe we are in agreement - particularly sinceC
is the onlyintent(out)
variable thenhide
is implied. However, it seems to me that even the example you linked illustrates howintent(in)
array dims must be handled explicitly to avoid issues (in that example, the interface defines how the array length is to be handled, which allows it to be optional). That's not done in the OP's code. Aside: By now, I think I could have just run an experiment, but I haven't :)
– Matt P
Mar 11 at 13:49
F2PY creates wrappers so that a Fortran subroutine can be called like a Python function (i.e. the intent(out) argument
C
becomes the return value of the function), and dimensions for automatic arrays do not need to be passed explicitly, see this example in the documentation. So I don't believe that is the problem in this case.– jbdv
Mar 11 at 8:10
F2PY creates wrappers so that a Fortran subroutine can be called like a Python function (i.e. the intent(out) argument
C
becomes the return value of the function), and dimensions for automatic arrays do not need to be passed explicitly, see this example in the documentation. So I don't believe that is the problem in this case.– jbdv
Mar 11 at 8:10
@jbdv That surpises me a bit based on my reading of the docs here (see 'intent', especially 'in', 'out', and 'hide'). Not to say that things don't 'work out' in some cases even without doing so. I'd have to experiment to know more.
– Matt P
Mar 11 at 13:11
@jbdv That surpises me a bit based on my reading of the docs here (see 'intent', especially 'in', 'out', and 'hide'). Not to say that things don't 'work out' in some cases even without doing so. I'd have to experiment to know more.
– Matt P
Mar 11 at 13:11
As I read that,
C
which is intent(out)
in Fortran, the F2PY intent out and hence hide implies that "The argument is considered as a return variable" and "The argument is removed from the list of required or optional arguments", so when called from Python, C
should not be passed to the function, but is the function's return value.– jbdv
Mar 11 at 13:39
As I read that,
C
which is intent(out)
in Fortran, the F2PY intent out and hence hide implies that "The argument is considered as a return variable" and "The argument is removed from the list of required or optional arguments", so when called from Python, C
should not be passed to the function, but is the function's return value.– jbdv
Mar 11 at 13:39
While the arguments defining array dimensions
K
, L
and M
are Fortran intent(in)
and will get the F2PY attributes intent in and optional, so that they can, but don't have to, be passed to the wrapped function (but are inferred from and checked against the passed array arguments grid_t
, eval_grid
and grid_x
). I may very well be wrong, but I believe this is not what's causing the OP's problems– jbdv
Mar 11 at 13:43
While the arguments defining array dimensions
K
, L
and M
are Fortran intent(in)
and will get the F2PY attributes intent in and optional, so that they can, but don't have to, be passed to the wrapped function (but are inferred from and checked against the passed array arguments grid_t
, eval_grid
and grid_x
). I may very well be wrong, but I believe this is not what's causing the OP's problems– jbdv
Mar 11 at 13:43
@jbdv Regarding
C
, I believe we are in agreement - particularly since C
is the only intent(out)
variable then hide
is implied. However, it seems to me that even the example you linked illustrates how intent(in)
array dims must be handled explicitly to avoid issues (in that example, the interface defines how the array length is to be handled, which allows it to be optional). That's not done in the OP's code. Aside: By now, I think I could have just run an experiment, but I haven't :)– Matt P
Mar 11 at 13:49
@jbdv Regarding
C
, I believe we are in agreement - particularly since C
is the only intent(out)
variable then hide
is implied. However, it seems to me that even the example you linked illustrates how intent(in)
array dims must be handled explicitly to avoid issues (in that example, the interface defines how the array length is to be handled, which allows it to be optional). That's not done in the OP's code. Aside: By now, I think I could have just run an experiment, but I haven't :)– Matt P
Mar 11 at 13:49
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55065728%2fexecute-fortran-subroutine-through-parallel-python-impossible-to-execute%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you edit in the full stack trace of the error?
– ruohola
Mar 8 at 14:58
I'm not familiar with the parallel python package, but somewhat with F2PY. You get an error message that "'module' object has no attribute 'matrix_op'", that could indicate that the function is not being loaded. You import the F2PY module design_operation as fdp, but you do not show where the
fdp.matrix_op
is being used? How islist_append
defined in your code?– jbdv
Mar 11 at 8:15