Hi guys,
I have a program using an XS package (to use a C librarie with a driver), this package has 3 subroutines to:
- load the library
- run the C code on the specified file
- close the library
I am calling this package from another perl script and I need to load and close the library once and run the C code about 3000 times, which takes a while. So I want to run that in parallel (the cpu is used at about 25% for one instance running so I should be able to run 3 of those at the same time, right?).
I don't need any variable from the main script except the name of the file to run (P.1.txt to P.3000.txt) on and the results from the C code running is printed out in one and only one file (stats.txt)...
I have read that fork has issues with XS sub, I however tried the Parallel:ForkManager package but it is not working fine either...and moreover I don't need a copy of each variable from the main script for each of my process, so I don't thing fork is ideal anyways. (Maybe I should precise that the main script is using a huge chunck of memory (1.5GB) so I really don't want to duplicate that..)
I tried to use threads, but I got a segmentation fault (certainly because of that same file the different processes are printing in and I did see you can share variable but not files and the printing process in inside the compiled C code)
I tried each one of these options with basic subroutine and it worked fine...
Would anyone have an idea of the possibilities (I tried a search in this forum and in google groups for parallel and XS language but didn't get any good result...)
Any help would be greatly appreciated...
Thanks a lot!
Eve
I have a program using an XS package (to use a C librarie with a driver), this package has 3 subroutines to:
- load the library
- run the C code on the specified file
- close the library
I am calling this package from another perl script and I need to load and close the library once and run the C code about 3000 times, which takes a while. So I want to run that in parallel (the cpu is used at about 25% for one instance running so I should be able to run 3 of those at the same time, right?).
I don't need any variable from the main script except the name of the file to run (P.1.txt to P.3000.txt) on and the results from the C code running is printed out in one and only one file (stats.txt)...
I have read that fork has issues with XS sub, I however tried the Parallel:ForkManager package but it is not working fine either...and moreover I don't need a copy of each variable from the main script for each of my process, so I don't thing fork is ideal anyways. (Maybe I should precise that the main script is using a huge chunck of memory (1.5GB) so I really don't want to duplicate that..)
Code:
.....
XSMat3::load();
$pm=new Parallel::ForkManager(3);
foreach $file (@filesToProcess)
{
$pm->start and next;
print "file being processed=$file\n";
XSMat3::driver("/swan/output/spectra/$file");
$pm->finish;
}
$pm->wait_all_children;
XSMat3::terminate();
...
I tried to use threads, but I got a segmentation fault (certainly because of that same file the different processes are printing in and I did see you can share variable but not files and the printing process in inside the compiled C code)
Code:
$t = threads->create(\&XSMat3::driver,"/swan/output/spectra/$file");
I tried each one of these options with basic subroutine and it worked fine...
Would anyone have an idea of the possibilities (I tried a search in this forum and in google groups for parallel and XS language but didn't get any good result...)
Any help would be greatly appreciated...
Thanks a lot!
Eve