简单的多线程流水线模型(一)

详解MegatronLM流水线模型并行训练(Pipeline Parallel) MegatronLM的第二篇论文是2021年出的,GPT-3模型参数已经达到了175B参数,GPU显存占用越来越多,训练时间也越来越长, 在本文中,MegatronLM结合了tensor模型并行、pipeline模型并行和数据并行来提升整体的训练速度,以及解决大模型在多机上的扩展性问题。在pipeline模型并行上提出了方法,提升了10%的吞吐。 阅读详情

流水线这个概念应该比较好理解,如一个工厂里,有一堆原料 --> 工人1加工 --> 工人2加工  --> 工人3加工 --> ... ->形成最终的产品。

下面写个简单的流水线实现的模型。


以工人2为例分析工人的整个工作过程:

循环开始:

  a.等待工人1的输入,要是工人1没输入,工人2就趴在工作台上睡觉。

  b.工人1有输出给工人2,发现工人2此时在睡觉呢,空闲着呢,因此工人1把东西往工人2的工作台上一扔,吼一声把工人2 叫醒。

  c.工人2拿到输入后,开始忙活,一阵手忙脚乱。

      此时要是工人1干得快,有输入给工人2,工人2就会嚣张得说,给老子等着,没看见老子正忙活呢!先睡觉去吧你,等老子忙完了叫你起来。工人1就老老实实睡觉去了。

  d.工人2把输入加工完,就会一直等到工人3空闲了,把东西丢给工人3,才算处理完成。

  e.工人2 处理完啦,就对工人1大吼一声,“给老子起来,快把东西给我,老子要干活”。(工人1醒来后第一件事当然是尽快把手头的活忙完然后把输入给工人2了。)

继续从a开始循环。


下面先从一个简单的例子开始,一步一步实现整个流水线(这里没做一些错误检查等等)。

假设现在我们有个一worker,它的任务就是接收一个数字input,如果 input>3,它就睡眠 input秒后醒来,如此循环。

error.h

#ifndef __errors_h
#define __errors_h

#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef DEBUG
# define DRPRINTF(arg) printf arg
#else
# define DRPINTF(arg)
#endif

#define err_abort(code,text) do { \
  fprintf(stderr, "%s at \"%s\":%d: %s\n",text, __FILE__,__LINE__,strerror(code));\
  abort();\
  } while(0)

#define errno_abort(text) do{\
  fprintf(stderr, "%s at \"%s\":%d: %s\n",\
    text, __FILE__,__LINE__,strerror(errno));\
	abort();\
	}while(0)
#endif

main.c

#include <pthread.h>
#include <time.h>
#include "errors.h"

/**
worker_type,一个worker实体的数据结构。 mtx是访问整个工人实体的锁。另外工人需要两个谓词(来标注自己的状态1.has_input,是否有输入,2.has_finished,是否已经处理完)
    thread_worker是工人实际工作的线程,工人有指向下一个工人的指针next。
    其它成员时可选的,根据实际情况和需要,这里我设置了两个成员,一个工人的名字,还有一个整形的输入。
*/
struct worker_type{
	pthread_mutex_t  mtx;
	pthread_cond_t cond_has_input;
	pthread_cond_t cond_has_finished;
	int has_input;
	int has_finished;

	pthread_t thread_id;
	void * (*thread_worker)(void *);// The thread of this worker
	struct worker_type * next;

	//below if optionally, corresponding to your demands
	char *name;                     // The worker's name
	int  input_data;                // The input data

};
typedef struct worker_type worker_t;

/**
pipeline_type,流水线的数据结构,因为这个例子并没用到多个工人,所以这个结构还不完整。
*/
typedef struct pipeline_type{
	int       count;
    worker_t * head;
    worker_t * tail;
}pipeline_t;
/**
工人干活的线程,基本循环:
1.等待前干些准备工作;
2.等待输入;注意这里pthread_cond_timewait和pthread_cond_wait在等待的过程是这样的:首先释放锁,等待信号,拿到信号后,请求锁,直到拿到锁之后函数才返回(如果设置超时就超时后返回)。
3.处理输入;
4.发送信号,解锁
*/
void * thread_worker(void *arg)
{
    //1. Before looping ,do something initial.
    worker_t * worker = (worker_t *)arg;
    struct timespec t;
	int status;
	int input;
	t.tv_nsec = 0;
	//2. Looping
    while(1){
	    //2.1 Lock the worker before access its value
		pthread_mutex_lock(&worker->mtx);

        //2.2 Waiting for the input
	    while(!worker->has_input){
		    //2.2.1  Do something while waiting
#if 0
			printf("Has something to eat? I just wait for 3s to answer\n");
			t.tv_sec = time(0)+3;
			//       Here you can set timeout and do other thing after timeout.
			status = pthread_cond_timedwait(&worker->cond_has_input,&worker->mtx,&t);
			if(status == ETIMEDOUT){
				printf("Nothing to eat,KFC!\n");
			}
#endif
			printf("Hello,can I help you?\n");
			status = pthread_cond_wait(&worker->cond_has_input,&worker->mtx);
		}

		//2.3 Fetch the input,processing
		input = worker->input_data;
		printf("Oh,yes! Has something to eat! Eat it! Let me eat %d\n",input);
		sleep(input);//process
		worker->has_input = 0;
		worker->has_finished = 1;

		//2.4 After processing, send the signal and unlock the mutex
		pthread_cond_signal(&worker->cond_has_finished);
		pthread_mutex_unlock(&worker->mtx);
	}
}
/**
下面这个是两个工人间处理工作交接的过程。
例如:工人1试图访问工人2的状态,等到工人2发信号说他把活干完了,才把东西塞给工人2,然后发送信号给工人2。
*/
void * send_input_to_worker(worker_t *worker, int input)
{
    //1. Catch the lock
	pthread_mutex_lock(&worker->mtx);
	//printf("Input %d get lock\n",input);
	//2. Waiting for the worker finish the job
	while(!worker->has_finished){
	    // Do something while waiting, here you can use the timeout option too.
		//printf("Input %d wait for eat end, unlock\n",input);
		pthread_cond_wait(&worker->cond_has_finished,&worker->mtx);
	}
	//3. Pass the input to the worker.
	//printf("Input %d get lock again\n",input);
	if(input > 3){
		worker->has_input = 1;
		worker->has_finished = 0;
		worker->input_data = input;
		pthread_cond_signal(&worker->cond_has_input);
	}
	//4. Unlock
	pthread_mutex_unlock(&worker->mtx);
	return NULL;
}
/**
这个流水线并不完整,这里只初始化了一个工人,另外一个工人就是我们自己啦,main函数,接收输入然后丢给工人。
*/
void *pipe_line_start_1(pipeline_t * pipeline_p)
{
    worker_t *worker_p;
    pipeline_p->head = (worker_t *)malloc(sizeof(worker_t));

	//initial the head worker
	worker_p = pipeline_p->head;
	worker_p->name = "Lucy";
	worker_p->thread_worker = thread_worker;
	worker_p->has_input = 0;
	worker_p->has_finished = 1;
	pthread_mutex_init(&worker_p->mtx,NULL);
	pthread_cond_init(&worker_p->cond_has_input,NULL);
    pthread_create(&worker_p->thread_id,NULL,worker_p->thread_worker,worker_p);

	return NULL;
}
int main(int argc, char *argv[]){
    int i;
    pipeline_t pipeline1;
	pipe_line_start_1(&pipeline1);

	while(1){
		scanf("%d",&i);	
		send_input_to_worker(pipeline1.head,i);
	}
	pthread_exit(NULL);
	return 0;
}

未完,待续...


  


MIPS CPI.cpp(计算越级前馈流水线CPI的C语言模型) 本程序通过C语言来实现了对流水线CPI的计算,核心在于考虑了越级前馈与原始五级流水线的比较,采用随机算法。 立即下载

相关推荐

[VisionPro] CogPMAlignTool 工具详解

[VisionPro] [CogPMAlignTool] [模板匹配]

weixin_43163656的博客 1万+

Go并发模型:流水线模型

Go作为一个实用主义的编程语言,非常注重性能,在语言特性上天然支持并发,Go并发模型有多种模式,通过流水线模型系列文章,你会更好的使用Go的并发特性,提高的程序性能。 这篇文章主要介绍流水线模型的流水线概念,后面文章介绍流水线模型的FAN-IN和FAN-OUT,最后介绍下如何合理的关闭流水线的协程。 Golang的并发核心思路 Golang并发核心思路是关注数据流动。数据流动的过程交给channel,数据处理的每个环节都交给goroutine,把这些流程画起来,有始有终形成一条线,那就能构成流水线模型。 但

稻草人技术博客 1348

【LTspice】005 伯德图绘制

目录 1 伯德图介绍 2 LTspice 截止频率验证 3 LTspice中如何添加光标 4 LTspice中如何将 幅频 和 相频曲线分开 1 伯德图介绍 Bode图由对数幅频特性和对数相频特性两张图组成。伯德图_百度百科 (1)对数幅频特性曲线 对数幅频特性是频率特性的对数值L(ω)=20lgA (ω)(dB)与频率ω的关系曲线;对数幅频特性的纵轴采用线性分度,为幅值的分贝数,即 L(ω)=20lgA(ω),A(ω)每增加10倍,L(ω)增加20dB;横坐标采用对数分度,即横轴上的ω取

m0_59642765的博客 1万+

电子科技大学计算机系统结构复习笔记(三):流水线技术

本复习笔记基于叶老师的课堂PPT,供自己期末复习与学弟学妹参考用。流水线是利用执行指令操作之间的并行性,实现多条指令重叠执行的技术。

Vec_Kun的博客 5680

数字逻辑Fundamentals of Digital Logic with Verilog Design | 3rd Edition Solutins Chapter 2(step by step)

数字逻辑第二章习题和详细步骤 2-1 ~ 2-78

weixin_62651190的博客 2312

手把手教你学simulink(90.1)--直流电动机实例:基于Simulink的基本模型的直流电动机(DC Motor)建模

直流电动机(DC Motor)因其结构简单、控制方便和良好的调速性能,广泛应用于各种工业自动化、机器人技术、家用电器以及航空航天等领域。为了更好地理解和应用直流电动机的工作原理及其控制系统,本项目旨在通过Simulink对直流电动机进行基本模型的建模与仿真。

MHD0815的博客 448

pthread之工作模式

<br />呵呵,本来只想写写今年学习多线程时碰到的一些问题,没有想到随意列个表,竟然成了一个系列,这一系列包含了互斥、条件变量、信号量等相关的内容、也包括了内存可视性、线程的取消等一些线程使用的高级话题。以这些知识为元素、以<br />现实现中遇到的问题为对象,为解决这些问题构成下面的几种基本的线程模型(就像编程语言中的for,while,if,switch这些编程的基本结构一样)<br />线程编程模型<br />流水线<br />每个线程反复地在数据系列上执行同一种操作,并把操作结果传递给下一步骤<b

杀出条血路来 811

把 MCP Server 直接装进 SAP ABAP:用 Unlimited Display Tools 打通 Agentic SDK 与 SAP ECC / S/4HANA 的最后一公里

摘要:AI与SAP集成的MCP解决方案 企业在AI集成中面临工具链复杂、数据对接繁琐的挑战。Model Context Protocol (MCP)通过标准化工具与数据暴露方式,将集成复杂度从N×M降至N+M。在SAP生态中,MCP Server for SAP直接部署于ABAP层,利用DDIC/CDS视图对接各类Agent SDK,避免中间件风险。 MCP核心包含三类对象: Tools:带元数据的可执行动作 Resources:结构化上下文数据 Prompts:可参数化提示模板 ABAP层实现MCP Se

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 700

深入浅出:数据流水线管理(上)

在绝大部分企业的数据中台建设中,数据流水线的建设都是核心工作之一。数据流水线系统承担着将数据从原始形态转换到用户与业务应用可以直接使用的形态的整个过程。在绝大多数时候,这些工作必须是自动且...

LinkTime_Cloud的博客 3618

深入理解 Terraform 中的资源更新与管理

摘要:本文探讨Terraform处理AWS安全组名称变更时的行为。当修改不可变属性(如安全组名称)时,Terraform会创建新资源并删除旧资源。通过状态文件比对所需状态与实际状态,Terraform对不可变属性采用"先创建后删除"策略,对可变属性则直接更新。实例演示了修改安全组名称和关联EC2实例时的处理过程,强调理解资源属性可变性对基础设施管理的重要性。(149字)

2501_90323865的博客 475

【Linux】Windows11 安装 WSL2 并运行 Ubuntu 22.04 详细操作步骤

Windows 11 安装 WSL2 和 Ubuntu 22.04 指南 本文详细介绍在 Windows 11 上安装 WSL2 和 Ubuntu 22.04 的完整步骤,包括: WSL2 与 VirtualBox 的性能对比优势 系统版本检查与升级方法 两种安装方式(一键安装和手动安装) Ubuntu 22.04 的安装与配置 存储位置管理及迁移技巧 常用 WSL2 命令速查表 文章还提供了性能优化建议和常见问题解决方案,适合开发者和 Linux 爱好者快速搭建高效的开发环境。

No8g攻城狮的博客 2万+

简单的多线程流水线模型(二)

续上一篇《简单的多线程流水线模型(一)》 下面我们创建三个工人 Lucy,Lily,Lilei,他们干的活就是接收输入的秒数input,把睡眠input秒,然后把input-1丢给下一个工人。 这里做一下小结: 流水线模型的优缺点。 优点:一环扣一环,确保事情按顺序一个一个干完。 缺点:流水线的某个环节如果处理速度慢的话,会影响上游的整个流水线,所以流水线的瓶颈应该是花时间最多的那个环节

最帅惋红曲 1892

YOLOv11 改进 - Mamba | 集成Mamba-YOLO(AAAI 2025),Mamba-YOLOv11-B 替换骨干,破解全局依赖建模难题,实现高效实时检测

本文介绍Mamba YOLO,为图片物体识别提供了“又快又准”的新方案。传统CNN架构运行快但难以捕捉远距离关联物体,Transformer架构精度高但计算量呈平方级增长,而SSM虽计算量为线性级且能抓全局关联,但用于图片识别时细节定位不准。为此,Mamba YOLO做了三项关键优化:引入ODMamba骨干网络,解决自注意力的二次复杂度问题,且无需预训练;设计ODMamba宏观结构确定最佳阶段比例和缩放大小;采用多分支结构的RG块建模通道维度,解决SSM在序列建模中的不足。在COCO数据集测试中,其小版本推

魔改工程师的博客 862

Java多线程:(一)并发模型

并发系统可以使用不同的并发模型实现,不同的并发模型的线程通过不同的合作方式去处理任务 共享状态和分离状态(shared state and separate state) 共享状态:所有的线程分享某个状态,这个状态可能是一个object,共享状态可能碰到的问题有死锁,竞态等。 非共享状态:不同的线程之间不会有共享的数据,当不同的线程需要交流时,他们通过分享不可变的对象,或copy出一份数据给其...

wujingyicode的博客 582

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

多线程模型

 两种常用的线程模型 生产者-消费者模型 就是由一个线程生产任务,而另外一个线程执行任务,二个线程之间有一个共享数据区,这种数据结构可以用队列来表示,但是必须是并发同步的,也就是就共享数据队列同一时间只能允许一个线程进行访问。这种机制叫做同步访问,在JAVA里面用关键字synchorinized来标识对象是同步并发访问的。        

qq_26704959的博客 2524

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

.Net中的并行编程-5.流水线模型实战

自己在Excel整理了很多想写的话题,但苦于最近比较忙(其实这是借口)。。。。 上篇文章《.Net中的并行编程-4.实现高性能异步队列》介绍了异步队列的实现,本篇文章介绍我实际工作者遇到了处理多线程问题及基于异步队列底层数据结构的解决方案。 需求如下:1.提供数据服写入服务供上层应用调用,数据写入服务处理的吞吐量要达到60w/s每秒,也就是用户每秒发送60w的数据然后通过数...

weixin_30411819的博客 131

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

JAVA基础-多线程

程序、进程、线程 程序:由高级语言编写,然后在编译的过程中,被编译器/解释器转译为机器语言,从而得以执行 顺序执行时的主要特征包括顺序行,封闭性,可再现性 进程:进程是程序的一次执行,该程序可以和其他程序并发执行。是系统进行资源分配和调用的独立单位。每一个进程都有它自己的内存空间和系统资源。 进程是由程序、数据和进程控制块组成。 线程:是程序的执行单元,执行路径。是程序使用CPU的...

HelloWorld! 586

Java多线程-并发编程概念

Java多线程之并发编程模型

Eddy的博客 560

跟大佬聊天,被反问Redis6的多线程真的能提高性能吗?

redis6 出来有段时间了,这个版本有不少的亮点,比如 client cache、acl、resp3、io 多线程等。对于 redis6 的新功能代码看的差不多了,复杂点主要集中在 cache track 和 io thread 上,个人对 io 多线程的设计和性能表现有些不认同。😅压测数据本应该使用图表展现,奈何太懒.redis6 的 io 多线程到底实不实用?看你的需求了,个人建议上 redis 集群来扩展高并发的需求。

程序员高级码农的博客 982

多线程处理list_跟大佬聊天,被反问Redis6的多线程真的能提高性能吗?

转自:http://xiaorui.cc/archives/6918前言redis6 出来有段时间了,这个版本有不少的亮点,比如 client cache、acl、resp3、io 多线程等。对于 redis6 的新功能代码看的差不多了,复杂点主要集中在 cache track 和 io thread 上,个人对 io 多线程的设计和性能表现有些不认同。?压测数据本应该使用图表展现,奈何...

weixin_39649405的博客 193

几种多线程编程模型的比较

http://blog.csdn.net/muclenerd/article/details/41869073 几种模型的特点 工作组模型1.多个worker共享一个数据队列,所以每次dequeue时要先检查队列是否为空。不为空才能的返回消息。2.enqueue可以不用关心队列消息数,只需要enqueue然后通知线程即可。3.示例中,条件变量condDone是可选的。某些情况下需要知晓队列是否为空...

weixin_34279061的博客 85

多线程入门

多线程入门分布式操作系统线程简介 Introduction to Threads为什么需要多线程进程与线程线程状态图线程使用 Thread Usage为什么需要多线程合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公...

见不着太阳的蘑菇的博客 384

Java并发编程实战笔记(3)- 多线程并发编程模型

1、多线程 多线程的优点 资源利用率更好,例如在IO阻塞的时候,CPU可以去干一些其他的事情。 程序设计更简单 程序响应更快 多线程的代价 往往使设计更复杂,多线程之间的交互往往比较复杂,错误难以发现 上下文切换的开销,线程与线程之间的切换往往需要代价,这个代价也不得不考虑 势必增加资源消耗,线程之间的切换不仅要消耗CPU,而且还需要内存存储堆栈信息

心相印的专栏 483

Java并发编程:并发模型(共享状态,分离状态,并行工作机模型,流水线模型,反应/事件驱动系统,函数式并行)

每种并发模型都有其适用场景和优缺点,选择哪种模型取决于应用程序的需求、硬件特性以及性能要求。Java平台通过提供丰富的API和工具包,支持多种并发模型的实现,使开发者可以根据实际情况灵活运用。在Java并发编程中,有几个关键的并发模型和策略用于处理多线程环境下的任务分配与执行。

qq_33240556的博客 552

Day3 多线程编程模型之pipeline

《POSIX多线程程序设计》 多线程之流水线模型 示例代码: pipe_create函数创建一个链表,每一个结点,代表流水线中的一个状态,并在最后附件一个结果状态。之后,启动状态线程pipe_stage,此时stage->data_ready 尚为0,pipe_stage等待条件变量avail. 若主线程接受到的输入合法,则调用pipe_start函数,记录进入pipeline的数据...

weixin_34367845的博客 306
上一篇: 简单的key-value实现
下一篇: 简单的多线程流水线模型(二)
小灰马
博客等级 码龄17年 55粉丝 42原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址