multi-thread – Parallel MergeSort in C ++

I tried to implement MergeSort parallel in C ++, which also tracks how many comparisons are made and how many threads it uses:


int *original_array,*auxiliary_array;
std::mutex protector_of_the_global_counter;
int global_counter=0;
std::mutex protector_of_the_thread_counter;
int number_of_threads=0;

class Counting_Comparator {
    bool was_allocated;
    int *local_counter;
    Counting_Comparator() {
        local_counter=new int(0);
    Counting_Comparator(int *init) {
    int get_count() {return *local_counter;}
    bool operator() (T first, T second) {
        return first &x) {
    ~Counting_Comparator() {
        if (was_allocated) delete local_counter;

struct limits {
    int lower_limit,upper_limit,reccursion_depth;

void parallel_merge_sort(limits argument) {
    int lower_limit=argument.lower_limit;
    int upper_limit=argument.upper_limit;
    if (upper_limit-lower_limit<2) return; //An array of length less than 2 is already sorted.
    int reccursion_depth=argument.reccursion_depth;
    int middle_of_the_array=(upper_limit+lower_limit)/2;
    limits left_part={lower_limit,middle_of_the_array,reccursion_depth+1},
    if (reccursion_depth comparator_functor(&local_counter);

int main(void) {
    using std::cout;
    using std::cin;
    using std::endl;
    cout <<"Enter how many numbers you will input." <>n;
    try {
        original_array=new int(n);
        auxiliary_array=new int(n);
    catch (...) {
        std::cerr <<"Not enough memory!?" <>original_array(i);
    limits entire_array={0,n,0};
    clock_t processor_time=clock();
    try {
    std::thread root_of_the_reccursion(parallel_merge_sort,entire_array);
    catch (std::system_error error) {
        std::cerr <<"Can't create a new thread, error "" <

So what do you think about it?

How to activate the Mysql parallel query function?

Please help, how to activate the Mysql parallel query function to get started?
The MySQL version is 8.0.19.

mysql> show variables like 'innodb_parallel_read_threads';
| Variable_name                | Value |
| innodb_parallel_read_threads | 4     |
1 row in set (0.00 sec)

Judging by the execution plan, although the cost value is high, it does not trigger parallel queries.

mysql> explain analyze SELECT count( FROM b,a WHERE = AND < 10000G
*************************** 1. row ***************************
EXPLAIN: -> Aggregate: count(a.`name`)  (actual time=79199.970..79199.971 rows=1 loops=1)
    -> Inner hash join ( =  (cost=29804029261222.55 rows=29803521726988) (actual time=52129.791..79198.823 rows=9999 loops=1)
        -> Table scan on b  (cost=31.81 rows=18758239) (actual time=0.385..19630.712 rows=20000000 loops=1)
        -> Hash
            -> Filter: ( < 10000)  (cost=4909601.51 rows=15888229) (actual time=2.266..52117.583 rows=9999 loops=1)
                -> Table scan on a  (cost=4909601.51 rows=47669458) (actual time=2.262..48985.413 rows=50000000 loops=1)

1 row in set (1 min 19.25 sec)

Run strace in parallel with python

I have a doubt, I have a list of Pids and I need to make a script that executes multiple strace commands with each pid; and so listen to some processes.
This is my code, I am using subprocess and the problem is that the files are created with the pids but not empty.

for pid in PIDS:

multi-thread – Run Bash scripts in parallel

I would like to run a script several times in more than 10 folders in parallel. What I need to know is how to structure the arguments by number. My non-parallel script is:

For i in {1..10};
    do python "folder_"$i;

I have heard of mpirun but I am not sure how to structure the arguments by folder number or something similar.

labeling: how can I make Graph's edge labels parallel to an edge line or follow an edge curve?

Edge labels are always represented horizontally. I would like to rotate the label of any straight line edge so that the bottom of the label bounding box matches the edge.

There was an earlier publication (Comfortable Edge Labeling of Unaddressed Graph) that did this using EdgeRenderingFunction, but that EdgeShapeFunction replaced in v12. EdgeShapeFunction does not have access to the tag as EdgeRenderingFunction did.

Labels that follow a curved edge would be an advantage, but a parallel tangent would suffice somewhere along the edge.

c # – reading insecure bits in parallel

    private static IEnumerable InMemGetBooleanArray(Bitmap bitmap)
        BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format1bppIndexed);
        bool()() ba2 = new bool(bitmap.Height)();

            int PixelsPerByte = 8;
            int heightInPixels = data.Height;
            int widthInBytes = data.Width / PixelsPerByte;
            byte* PtrFirstPixel = (byte*)data.Scan0;

            Parallel.For(0, heightInPixels, y =>
                byte GetMask(int x)
                    return (byte)(0x80 >> (x & 0x7));

                void BitTest(int bx, int by)
                    byte ret = *(PtrFirstPixel + (by * data.Stride) + (bx >> 3));
                    ret &= GetMask(bx);
                    if (ret > 0)
                        ba2(y)(bx) = true;

                for (int x = 0; x < widthInBytes; x += PixelsPerByte)
                    ba2(y) = new bool(data.Width);
                    BitTest(x, y);
                    BitTest(x + 1, y);
                    BitTest(x + 2, y);
                    BitTest(x + 3, y);
                    BitTest(x + 4, y);
                    BitTest(x + 5, y);
                    BitTest(x + 6, y);
                    BitTest(x + 7, y);
        return ba2;

After referring to

I tried to build one for bitmaps of 1 bit per pixel. If you can review this, it would help me greatly to verify that this is the right way to do it.

Adding two matrices in parallel

Looking to add these two cells



… such that the output is (in a single cell, delimited by commas):


Really only iterating through the indices of each list (index 0 of list one + index 0 of list two, index 1 of list one + index 1 of list two, etc.) and maintaining the format x, y , z with comma delimiters.

I appreciate the help!

libraries: use two parallel instances of the same .NET assembly

I have an internal enterprise application .NET 4.6 of n levels. You have a business logic layer class library project that refers to a data access layer class library project. It is designed to decouple the two so that, in theory, a different data access assembly can be changed without modifying the BLL.

But a new idea has just entered the scene. We want to use these projects to also support a public website through a web service application. To help ease the database server load (trying to avoid SQL Enterprise licenses), we had the idea, "What if we do some of our large read-only queries from a replicated database, while we do less frequent insertions and updates in the master database? "

They will be identical databases, so my DAL still works on both, but it simply connects to the single connection string of your configuration file. I never planned to choose a data source at runtime, so there could also be others ApplicationSettings, static variables, possibly problems with the life management of DALs Entity Framework DbContext all my life … It seems that what I really need are two parallel instances of that assembly. I could do it by creating two separate web service applications for each place, but could it be done within a single application? I have the feeling that a total redesign with some type of DI configuration is probably what is needed for this use case, but I'm curious to know what the options are, if any, to run two parallel assembly instances / configurations .

python 3.x – Parallel mapping monitored through a Pandas data frame?

This code assigns a function on a parallel data set in a controlled way, and returns the result in the out variable:

import pandas as pd
import numpy as np
from tqdm import tqdm, trange
from joblib import Parallel, delayed
import multiprocessing
import math

n_jobs = multiprocessing.cpu_count()
df = pd.DataFrame(np.random.randn(10000, 200))
chunk_size = 32
n_chunks = min(len(df), int(math.ceil(len(df) / chunk_size)))

def func(x): # do something
    return x+1

out = Parallel(n_jobs=n_jobs, verbose=0)(
               df(i * chunk_size: (i + 1) * chunk_size)
             for i in trange(n_chunks))

What are the pros and cons of this approach? Are there better approaches? What if I need to map in place?

Focus: Do convex lenses make parallel light rays of different wavelengths converge at different points?

Do convex lenses make parallel light rays of different wavelengths converge at different points?

Yes. The separation of different wavelengths of light is called dispersion. Different wavelengths of light refract at different angles because the refractive index of a transparent medium is frequency dependent. We often describe different materials, such as crown glass, flint glass, diamond, water, etc., such as having an "index" of refraction, but that unique index is simply representative of refraction in a single length. cool. For example, in the List of Wikipedia refractive indices, many of the material indices are specified at a wavelength of 589.29 nm.

enter the description of the image here
Graph of the index of refraction against the wavelength of several glasses. The dispersion of a material is approximately the slope of the line through refractive indices at the boundary of the shaded region (optical wavelength) for a particular material. By DrBob, from Wikimedia Commons. CC BY-SA 3.0

A quantification of the quantity of dispersion in a particular refractive medium is called the Abbe number of that material. Approximately, the Abbe number is the ratio of the refractive index of the material in a particular yellow wavelength, to the difference between the refractive indices in the particular blue and red wavelengths. The higher the Abbe number, the less dispersion a material exhibits.

Dispersion is what causes longitudinal chromatic aberration in lenses (see also, What is chromatic aberration?), so that different wavelengths of light are focused at different focal distances.

enter the description of the image here
Diagram showing longitudinal chromatic aberration, by DrBob of Wikimedia Commons. CC BY-SA 3.0

This is corrected by joining two (or more) pieces of glass with different Abbe numbers. For example, an achromatic doublet uses a convex crown glass element with a concave flint glass element to reduce the variation in the focal lengths of the optical wavelengths of light.

enter the description of the image here
Achromatic doublet that corrects chromatic aberration, by DrBob of Wikimedia Commons. CC BY-SA 3.0

There are other corrective elements, such as apochromate Y superacromates.