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

type inference doesn't work in parallel code sections #1329

Open
robertwb opened this issue May 15, 2012 · 2 comments
Open

type inference doesn't work in parallel code sections #1329

robertwb opened this issue May 15, 2012 · 2 comments

Comments

@robertwb
Copy link
Contributor

The following example requires thread_id to be typed as int, even though the return type of parallel.threadid() is known.

def parallel_section():
    """
    >>> parallel_section()
    [1, 2, 3, 4, 5, 6, 7, 8, 9](0,)
    """
    #cdef int thread_id
    ids = []
    with nogil, parallel.parallel(num_threads=10):
        thread_id = parallel.threadid()   # id=0..9 for 10 threads
        with gil:
            ids.append( thread_id )
    return sorted(ids)

This is particularly annoying because it happens in a nogil section, so the code won't compile without explicitly typing the variable.

Migrated from http://trac.cython.org/ticket/774

@robertwb
Copy link
Contributor Author

scoder changed description from

The following example requires thread_id to be typed as int, even though the return type of parallel.threadid() is known.

def parallel_section():
    """
    >>> parallel_section()
    [1, 2, 3, 4, 5, 6, 7, 8, 9](0,)
    """
    #cdef int thread_id
    ids = [   with nogil, parallel.parallel(num_threads=10):
        thread_id = parallel.threadid()   # id=0..9 for 10 threads
        with gil:
            ids.append( thread_id )
    return sorted(ids)

This is particularly annoying because it happens is a nogil section, so the code won't compile without explicitly typing the variable.

to

The following example requires thread_id to be typed as int, even though the return type of parallel.threadid() is known.

def parallel_section():
    """
    >>> parallel_section()
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9](]
)
    """
    #cdef int thread_id
    ids = []
    with nogil, parallel.parallel(num_threads=10):
        thread_id = parallel.threadid()   # id=0..9 for 10 threads
        with gil:
            ids.append( thread_id )
    return sorted(ids)

This is particularly annoying because it happens is a nogil section, so the code won't compile without explicitly typing the variable.
commented

@robertwb
Copy link
Contributor Author

scoder changed description from

The following example requires thread_id to be typed as int, even though the return type of parallel.threadid() is known.

def parallel_section():
    """
    >>> parallel_section()
    [1, 2, 3, 4, 5, 6, 7, 8, 9](0,)
    """
    #cdef int thread_id
    ids = [   with nogil, parallel.parallel(num_threads=10):
        thread_id = parallel.threadid()   # id=0..9 for 10 threads
        with gil:
            ids.append( thread_id )
    return sorted(ids)

This is particularly annoying because it happens is a nogil section, so the code won't compile without explicitly typing the variable.

to

The following example requires thread_id to be typed as int, even though the return type of parallel.threadid() is known.

def parallel_section():
    """
    >>> parallel_section()
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9](]
)
    """
    #cdef int thread_id
    ids = []
    with nogil, parallel.parallel(num_threads=10):
        thread_id = parallel.threadid()   # id=0..9 for 10 threads
        with gil:
            ids.append( thread_id )
    return sorted(ids)

This is particularly annoying because it happens in a nogil section, so the code won't compile without explicitly typing the variable.
commented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant