Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Windows
Luis Guerrero
lguerrero@plainconce
pts.com
http://geeks.ms/blogs/l
uisguerrero/
http://bit.ly/TPLCodeMotion
Agenda
El porqu de la computacin paralela.
Buscando paralelismo en nuestras
aplicaciones.
Plataforma de computacin paralela en Visual
Studio 2010 y Windows 8.
Soporte de depuradores y profilers.
Luis Guerrero
lguerrero@plainconcepts.com Plain Concepts
Computacin paralela
POR QU?
Luis Guerrero
lguerrero@plainconcepts.com Plain Concepts
4000
4000
2007
2008
8000
8000
2009
2010
16000
16000
2011
2012
32000
32000
2013
2014
Luis Guerrero
lguerrero@plainconcepts.com Plain Concepts
S
Socket
C/
S
Cores / Socket
T/
C
App
Concurrency
Hardware
Threads / Core
Luis Guerrero
lguerrero@plainconcepts.com Plain Concepts
Computacin paralela
BUSCANDO
PARALELISMO EN
NUESTRAS
Buscando paralelismo
Buscando paralelismo en nuestras
aplicaciones a travs de:
Organizacin por tareas
Organizacin por datos
Organizacin por orden
Luis Guerrero
lguerrero@plainconcepts.com Plain Concepts
Tareas paralelas
Divide y vencers
{}
Pocas? Infrautilizacin.
{}
{}
{}
{}
{}
{}
Patrones
Patrones de cdigo
Fork / Join
Loop Parallel
Divide y vencers
Productor / Consumidor
Pipeline
Asynchronous Agents
Luis Guerrero
lguerrero@plainconcepts.com Plain Concepts
Execute
Merge
Luis Guerrero
lguerrero@plainconcepts.com Plain Concepts
Presentamos
Task
Es la nueva unidad mnima de ejecucin en
TPL, ya no se utiliza Thread.
Las tareas (Task) envuelven la ejecucin del
cdigo, para su ejecucin concurrente.
Luis Guerrero
lguerrero@plainconcepts.com Plain Concepts
Creacin de Task
Task task = new Task(() = > { });
Task< D ataItem > taskW ithResult = new
Task< D ataItem > (() = > { return new
D ataItem (); });
Esto slo define el objeto Task, no ejecuta el
cdigo.
Luis Guerrero
lguerrero@plainconcepts.com Plain Concepts
Creacin de Task II
Task.Factory.StartN ew (() = > { });
Task< int> .Factory.StartN ew (() = >
{ return 42; });
Este cdigo define y pone a ejecutar el objeto
Task.
Luis Guerrero
lguerrero@plainconcepts.com Plain Concepts
task.Start();
task.RunSynchronously();
task.Status = = TaskStatus.Running;
task.IsCom pleted;
task.IsFaulted;
Luis Guerrero
lguerrero@plainconcepts.com Plain Concepts
Enlazando tareas
Task task = new Task(() = > { });
task.ContinueW ith((previousTask) = > { });
Luis Guerrero
lguerrero@plainconcepts.com Plain Concepts
Luis Guerrero
lguerrero@plainconcepts.com Plain Concepts
Uso de bloqueos
ReaderW riterLockSlim rw ls = new ReaderW riterLockSlim ();
rw ls.EnterReadLock();
try
{
// tu cdigo aqu
}
fi
n ally
{
rw ls.ExitReadLock();
}
Luis Guerrero
lguerrero@plainconcepts.com Plain Concepts
PLINQ
PARALLEL LINQ
PLINQ
var q = from p in people
.AsParallel()
var q = from p in people
where p.Name == queryInfo.Name &&
where p.Name == queryInfo.Name &&
p.State == queryInfo.State
p.State == queryInfo.State
&&
&&
p.Year >= yearStart &&
p.Year >= yearStart &&
p.Year <= yearEnd
p.Year <= yearEnd
orderby p.Year ascending
orderby p.Year ascending
select p;
select p;
Luis Guerrero
lguerrero@plainconcepts.com Plain Concepts
Ms opciones de PLINQ
list.AsParallel().W ithCancellation(new CancellationToken(false));
list.AsParallel().W ithD egreeO fParallelism (Environm ent.ProcessorCount);
list.AsParallel().W ithExecutionM ode(ParallelExecutionM ode.ForceParallelism );
list.AsParallel().W ithM ergeO ptions(ParallelM ergeO ptions.AutoBuff
ered);
Luis Guerrero
lguerrero@plainconcepts.com Plain Concepts
Luis Guerrero
lguerrero@plainconcepts.com Plain Concepts
PROFILER &
DEBUGGER
Gracias