Quantcast
Channel: Fortran
Viewing all articles
Browse latest Browse all 3108

Within Fortran, Call Matlab

$
0
0

Hi,

I have a question about how to call Matlab script within Fortran, which performs Matlab parallel computing "parfor" syntax. Basically, I am solving a problem in Fortran which is mainly a Do-Loop. For each iteration, I write out a series from Fortran for a Matlab script to read in, process through "parfor", and write back to Fortran. Fortran iteration continues until convergence.

In my Fortran codes, I use call system to let the shell return to Linux commands and call matlab, run matlab script, exit matlab and return to Fortran.

      CALL system(" matlab -nodesktop -nojvm -r 'Matlab_script; exit'")

The codes look like the above. ifort compiles the entire program with no problem. Also, the entire Fortran program runs fine and the results are correct.

However, the problem is that within Matlab_script.m, a matlab parfor loop should be executed. Rather, the loop was executed in plain "for, ..., end" loop. It takes so long for Fortran to get back the matlab processed results. I tested the Matlab_script.m without Fortran call system() and the parfor loop goes fine. 

Does anyone know

1. is there a better way to let Fortran handle over to Matlab to process, wait and get back the results besides Call System() ?

2. Why call system does not implement the matlab parfor function?  

Please advise. Thank you so much!

Calvin

 


Viewing all articles
Browse latest Browse all 3108

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>