Perl multiprocessing on multi processors

Posted on 2005-04-11
Last Modified: 2010-05-18
Hi everyone

Just thought if anyone did this

create a perl application to assign multiple perl process and control those assignments to a multiple processors that reside on WinNT machine. if you have a sample code it would certanly help.

so this is basicaly control of the multiple process and to which processor the process gets assigned to.

highly appreciated

Question by:ledeni
    LVL 18

    Expert Comment

    I would suggest you leave process scheduling to the OS scheduler. Even if the OS is only Windows NT, it most likely does a better job than just assigning each process to a different CPU.

    Author Comment

    thanks kandura for your response ...

    unfortunately that does not seem to be a good thing at least for me since WintNT at least in my case, seem to shaf everything to 1st procesor untill full and then start looking at the other one ..

    Through perl I am creating a process that call another VERY high volume application and at least when I create a first process the 80 % of procesor is taken .. when I create a 2nd process the OS tries to put it into another 20% of available space within first procesor...

    for that reason I need an ability to control that.

    On the other hand I am using Win32::Process library to create multiple process .. do you know if there is anything better for that ??

    Thanks a bunch

    LVL 18

    Expert Comment

    sounds like WinNT does *not* do such a great job...

    Win32::Process sounds like the way to go. You could use the SetProcessAffinityMask method on the process.

    From the documentation:

        $ProcessObj->GetProcessAffinityMask($processAffinityMask, $systemAffinityMask)
            Get the process affinity mask. This is a bitvector in which each bit represents the processors that a process is allowed to run on.

            Set the process affinity mask. Only available on Windows NT.

    Not sure if they really mean a vec() thing, or just something like 0x01 & 0x02.

    Author Comment

    its Windoz what else to expect :)

    the hex val seem more appropriate .. do you know if I can pick up the num of process through perl so that I make it dynaminc instead of a static assignment of processors ???

    thanks a bunch
    LVL 18

    Expert Comment

    I have no idea how to get the number of CPU's on Windows. Win32::Perflib might help, or Win32::API. I'm sure it's a call in kernel.dll somewhere :-)
    LVL 18

    Accepted Solution

    Yup. Here you go :-)

        use Win32::API;
        typedef Win32::API::Struct SYSTEM_INFO => qw{
            int dwOemId;
            int dwPageSize;
            int lpMinimumApplicationAddress;
            int lpMaximumApplicationAddress;
            int dwActiveProcessorMask;
            int dwNumberOfProcessors;
            int dwProcessorType;
            int dwAllocationGranularity;
            int dwProcessorLevel;
            int dwProcessorRevision;
        Win32::API->Import('kernel32', 'BOOL GetSystemInfo(LPSYSTEM_INFO si)');
        my $si = Win32::API::Struct->new('SYSTEM_INFO');
        print "#cpus: ", $si->{dwNumberOfProcessors}, $/;

    Author Comment

    ata boy kendura .. thanks a bunch for your help

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
    On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This video discusses moving either the default database or any database to a new volume.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now