Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8985243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:17:19+00:00 2026-06-15T21:17:19+00:00

So, I am considering to make a C extension of a python component that

  • 0

So, I am considering to make a C extension of a python component that I’ve got. Then, I thought of using OMP to take as much advantage as I can from the machines that will, eventually, run the combined solution of Python+C.

Has anyone tried something similar at all? Are there any particular, unpropitious, details than could make such a solution fail?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:17:20+00:00Added an answer on June 15, 2026 at 9:17 pm

    I have done this successfully for large data mining tasks in radio astronomy. See https://github.com/ewanbarr/sigpyproc.git for an example.

    The thing to note is that the C libraries I built in these cases are accessed via ctypes and not as native Python extensions.

    So, for example:

    Python: test.py

    import ctypes as C
    import numpy as np
    from numpy.ctypeslib import as_ctypes
    lib = C.CDLL("libmytest.so")
    
    def set_N_threads(nthreads):
        self.lib.omp_set_num_threads(nthreads)
    
    def do_some_task(input_array):
        input_array = input_array.astype("float32")
        output_array = np.empty_like(input_array)
        lib.do_some_omp_task(as_ctypes(input_array),
                             as_ctypes(output_array),
                             C.c_size_t(input_array.size))
        return output_array
    

    C: test.c

    #include <omp.h>
    
    void do_some_omp_task(float* input_array,
                          float* output_array,
                          size_t size)
    {
       int ii;
    #pragma omp parallel for default(shared) private(ii)
       for (ii=0;ii<size;ii++)
           do something using ii and the arrays
    }
    

    Compile:

    gcc -O3 -lm -fopenmp -fPIC -c test.c -o test.o
    gcc -shared -lgomp -o libmytest.so test.o
    

    To answer your question, I have had no problems with this kind of setup and the speed improvements achievable have been impressive (although the above example wouldn’t really benefit from OMP)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I'm considering using Python to make a watchdog app on Windows XP that
I want to make my C++ project cross platform, and I'm considering using Cygwin/MinGW.
I'm considering trying to make a game that takes place on an essentially infinite
I am considering using class extension as a way to connect my model with
I am considering building a website using ClojureScript. Does it make sense to write
So I'm thinking about creating a simple component that I would be using on
Considering that simple java code which would not work: public class Bar extends AbstractBar{
Considering that I have a Schema named SBST I want to find all empty
Considering that the two machine's time settings are not synced, is it still possible
My code is using a third party library that employ a singleton pattern deep

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.