首页 > 其他分享 >What's PLinq? how to use it?

What's PLinq? how to use it?

时间:2023-04-19 16:12:27浏览次数:37  
标签:What use Parallel AsParallel how query data parallel PLinq

What's PLinq? how to use it?

PLinq stands for "Parallel LINQ", which is a parallel implementation of LINQ (Language-Integrated Query) in .NET. It allows developers to perform LINQ queries in parallel by automatically partitioning the input data into smaller chunks and processing them concurrently.

To use PLinq, you first need to ensure that your data source is suitable for parallelism. This typically means that the data source can be partitioned into smaller chunks that can be processed independently. Once you have a suitable data source, you can use the AsParallel extension method to create a PLinq query. For example:

 
int[] data = new int[] { 1, 2, 3, 4, 5 };
var query = data.AsParallel().Where(x => x % 2 == 0).Select(x => x * x);

In this example, the data array is first converted to a parallel data source using the AsParallel method. The Where and Select operations are then performed in parallel on the chunks of data, with the results automatically combined at the end.

PLinq also provides additional features such as load balancing, which ensures that each processor gets an equal amount of work, and cancellation, which allows you to cancel a long-running query if needed.

 

difference between AsParallel and Parallel.Foreach

Both AsParallel and Parallel.ForEach are part of the PLINQ library in C# and can be used for parallel processing of data. However, they differ in the way they parallelize the data.

AsParallel is a method that can be called on an IEnumerable collection to make it parallel. It internally uses the Task Parallel Library (TPL) to execute the query in parallel. The AsParallel method converts the sequence into a Parallel LINQ (PLINQ) query, which can then be processed on multiple cores. Once the query has been parallelized, LINQ operators such as Where, Select, Aggregate, and Join can be applied on the data.

Parallel.ForEach is a parallel equivalent of the traditional foreach loop. It allows the user to loop over a collection and perform an action on each item in parallel. It internally creates a Task for each item in the collection and distributes the work across multiple cores. It also provides an option to specify the degree of parallelism, which allows you to control how many parallel tasks should be created.

In summary, AsParallel is used to parallelize a LINQ query, while Parallel.ForEach is used to perform an action on each item in a collection in parallel.

 

标签:What,use,Parallel,AsParallel,how,query,data,parallel,PLinq
From: https://www.cnblogs.com/chucklu/p/17333647.html

相关文章

  • 本地升級stable-diffusion diffuser docker CUDA11.7 RTX2060
    1.0前言本地搭建stable-diffusiondiffuserdockerCUDA10.2RTX2060上次安裝的cuda10.2太舊了,升級cuda11.7順便填一下漏了的點。2.0卸載sudoapt-getremove--purge'^nvidia-.*'sudoapt-getremove--purge'^libnvidia-.*'sudoapt-getremove--purge'^cuda-.*&......
  • 云时代,MySQL到ClickHouse数据同步产品对比推荐
    ClickHouse在执行分析查询时的速度优势很好的弥补了MySQL的不足,但是对于很多开发者和DBA来说,如何将MySQL稳定、高效、简单的同步到ClickHouse却很困难。本文对比了NineData、MaterializeMySQL(ClickHouse自带)、Bifrost三款产品,看看他们在同步时的差异。对比结果概述整体上......
  • 好用的字符串搜索库 - Fuse.js
    https://github.com/krisk/Fuse OptionsFollow#BasicOptions#isCaseSensitiveType: booleanDefault: falseIndicateswhethercomparisonsshouldbecasesensitive.#includeScoreType: booleanDefault: falseWhetherthescoreshouldbeincludedinthe......
  • 报错解决:user.Case: (models.E020) The 'Case.check()' class method is currently ov
    Django在启动时报错,如下:user.Case:(models.E020)The'Case.check()'classmethodiscurrentlyoverriddenby<django.db.models.query_utils.DeferredAttributeobjectat0x0000020331E0AE20>.意思是说:在user.Case.check()在执行的过程中被【django.db.models.query_ut......
  • 定义一个User结构体
    d:一个数字,每个用户不同的idemail:email地址,一般网站的用户允许以email地址登录gender:性别,男or女QQ:QQ号码写一个函数,在User数组中查找某个id的User函数描述:User*find(User*all,intn,intid);其中,all:输入一个User数组n:数组长度id:待查找的id#include<iostream>......
  • is blocked because of many connection errors; unblock with 'mysqladmin flush-hos
    指定允许连接不成功的最大尝试次数。5.7默认是100;如果到达这个数,那么服务器将不再允许新的连接,即便mysql仍正常对外提供服务。所以可以将这个参数设置为几万。showvariableslike'max_connect_errors';//最大链接错误次数可以提供最大的链接错误次数setglobalmax_conn......
  • Konga versions equal to or below v0.14.9 use the default TOKEN_SECRET
    VulnerabilityDescriptionKongisaclould-native,fast,scalable,distributedmicroserviceabstractionlayer(alsoknownasAPIgateway,APImiddlewareorinsomecasesservicegrid)framework,repositoryaddress:https://github.com/Kong/kong,officialw......
  • 配置SUSE linux实例的NTP/Chrony时钟同步服务
    问题描述您希望了解如何修改Linux系统的ECS实例的时区,以及如何开启、配置及使用NTP/Chrony服务,保证实例的时间精确同步。适用于SUSELinuxEnterpriseforSAP12SUSELinuxEnterpriseforSAP15说明和使用限制NTP服务的通信端口为UDP123,您需要在实例安全组的入方向......
  • Vue 登录login post请求 security UserDetailsService 获取参数为""
    背景原请求将数据放到params中,导致数据拼接在请求地址后面,具有高级安全隐患。请求方法:axios.request({url:'/login',method:'post',params:{username:'****',password:'****'}})出现的问题将params改成data,使数据放在请求体中,但后端自定义的U......
  • 抓包显示”TCP Port number reused“端口重复使用
    访问linux指定端口失败在一次调试中,在windows平台下使用软件,访问linux系统的8554端口失败,于是使用windows系统抓包查看;看到linux系统8554端口回复给windows系统14676端口的内容:win=0滑动窗口大小为0、Len=0长度为0;并且windows系统访问linux系统时“TCPPortnumberreused:重......