Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

[BUG] parallelize should abort if num_workers < 0, currently it has weird behavior #3312

Closed
SynodicMonth opened this issue Jul 26, 2024 · 3 comments
Assignees
Labels
bug Something isn't working mojo-repo Tag all issues with this label

Comments

@SynodicMonth
Copy link
Contributor

Bug description

from algorithm import parallelize

def main():
    @parameter
    fn parallel(i: Int):
        print(i, end='')
    
    parallelize[parallel](10, 0)

when num_workers=0, the parallel fn does not execute.

Steps to reproduce

Also,

from algorithm import parallelize

def main():
    @parameter
    fn parallel(i: Int):
        print(i, end='')
    
    parallelize[parallel](10, -1)

num_workers<0 causes wierd output

when num_workers=-1:

12043

when num_workers=-2:

3012

System information

- Ubuntu 22.04.4 LTS
- mojo 24.4.0 (2cb57382)
- modular 0.8.0 (39a426b5)
@SynodicMonth SynodicMonth added bug Something isn't working mojo-repo Tag all issues with this label labels Jul 26, 2024
@martinvuyk
Copy link
Contributor

Hi, thanks for catching this.

when num_workers=0, the parallel fn does not execute.

That makes absolute sense to me, you're telling it to execute a function with 0 threads and it does exactly that. It's the same as doing:

for i in range(0):
    print("hi")

it will do nothing 🤷‍♂️

num_workers<0 causes wierd output

This can probably be a quick fix by doing max(0, num_workers) (or aborting if num_workers < 0). Could you change the title of the issue to refer to that so that this can be fixed by the Mojo team ? (parallelize is not open sourced yet so I can't make a PR)
(reproducible with mojo 2024.7.2605)

@SynodicMonth SynodicMonth changed the title [BUG] parallelize won't run when num_workers=0 [BUG] parallelize should abort if num_workers < 0, currently it has weird behavior Jul 27, 2024
@SynodicMonth
Copy link
Contributor Author

Yeah that make sense.

Actually this is associated to another bug #3311, where a global variable initialized from num_performance_cores() become 0 after compile. Then the whole parallel body just don't execute.

Since num_work_items is not zero, if num_workers=0, the program would better complain it can't excecute instead of just don't execute.
Or we should clarify this in the doc and let the user to add some check.

I've changed the title

@ehein6 ehein6 self-assigned this Aug 7, 2024
@ehein6 ehein6 closed this as completed Aug 8, 2024
Copy link
Collaborator

This should be fixed in the upcoming nightly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

4 participants