Products
  • Wolfram|One

    The definitive Wolfram Language and notebook experience

  • Mathematica

    The original technical computing environment

  • System Modeler

    Multidomain modeling and simulation of complex systems

  • Compute ServicesUse with Mathematica and Wolfram|One
  • AI AccessUse with Mathematica and Wolfram|One
  • Finance Platform
  • Wolfram|Alpha Notebook Edition
  • Application Server
  • Enterprise Private Cloud
  • Wolfram Engine
  • Wolfram Player
  • Wolfram Cloud App
  • Wolfram Player App

More mobile apps

Wolfram|Alpha

  • Wolfram|Alpha Website
  • Wolfram|Alpha APIs

AI Products

  • Wolfram AI Ecosystem
  • Wolfram Foundation Tool
  • Wolfram Cloud MCP
  • Wolfram Local MCP
  • Agent One API
  • CAG Component APIs

Core Technologies of Wolfram Products

  • Wolfram Language
  • Computable Data
  • Wolfram Notebooks
  • Linguistic Understanding

Additional Deployment Options

  • Wolfram Cloud
  • Wolfram Web Engine
  • wolframscript
  • WSTPServer
  • Group & Organizational Licensing
  • All Products
Consulting & Solutions

We deliver solutions for the AI era—combining symbolic computation, data-driven insights and deep technical expertise

Wolfram Consulting

Data Science, Finance & Business

  • Artificial Intelligence
  • Data Science
  • Healthcare
  • Real Estate

Engineering

  • Civil Engineering
  • Automotive Engineering
  • Sustainable Energy

Science & Technology

  • AgTech
  • Biosciences
  • Environmental Science
  • Food Science
  • Quantum Computation
  • Social and Behavioral Sciences

More Wolfram Solutions

Technology for Education

  • Research Universities
  • Colleges & Teaching Universities
  • High Schools
  • Resources for Students

Education Initiatives

  • Next-Gen EdTech
  • Computer-Based Math

More Solutions for Education

  • Contact Us
Learning & Support

Get Started

  • Wolfram Language Introduction
  • Fast Intro for Programmers
  • Fast Intro for Math Students
  • Wolfram Language Documentation

More Learning

  • Highlighted Core Areas
  • Demonstrations
  • YouTube
  • Daily Study Groups
  • Wolfram Schools and Programs
  • Books

Grow Your Skills

  • Wolfram U

    Courses in computing, science, life and more

  • Community

    Learn, solve problems and share ideas.

  • Blog

    News, views and insights from Wolfram

  • Resources for

    Software Developers

Tech Support

  • Contact Us
  • Support FAQs
  • Support FAQs
  • Contact Us
Company
  • About Wolfram
  • Career Center
  • All Sites & Resources
  • Connect & Follow
  • Contact Us

Work with Us

  • Student Ambassador Initiative
  • Wolfram for Startups
  • Student Opportunities
  • Jobs Using Wolfram Language

Educational Programs for Adults

  • Summer School
  • Winter School

Educational Programs for Youth

  • Middle School Camp
  • High School Research Program
  • Computational Adventures

Read

  • Stephen Wolfram's Writings
  • Wolfram Blog
  • Wolfram Tech | Books
  • Wolfram Media
  • Complex Systems

Educational Resources

  • Wolfram MathWorld
  • Wolfram in STEM
  • Wolfram Challenges
  • Wolfram Problem Generator

Wolfram Initiatives

  • Wolfram Science
  • Wolfram Foundation
  • History of Mathematics Project

Events

  • Stephen Wolfram Livestreams
  • Online & In-Person Events
  • Contact Us
  • Connect & Follow
For AIs
  • Your Account
  • User Portal
  • Wolfram Cloud
  • Products
    • Wolfram|One
    • Mathematica
    • System Modeler
    • Compute ServicesUse with Mathematica and Wolfram|One
    • AI AccessUse with Mathematica and Wolfram|One
    • Finance Platform
    • Wolfram|Alpha Notebook Edition
    • Application Server
    • Enterprise Private Cloud
    • Wolfram Engine
    • Wolfram Player
    • Wolfram Cloud App
    • Wolfram Player App

    More mobile apps

    • Wolfram|Alpha
      • Wolfram|Alpha Website
      • Wolfram|Alpha APIs
    • AI Products
      • Wolfram AI Ecosystem
      • Wolfram Foundation Tool
      • Wolfram Cloud MCP
      • Wolfram Local MCP
      • Agent One API
      • CAG Component APIs
    • Core Technologies
      • Wolfram Language
      • Computable Data
      • Wolfram Notebooks
      • Linguistic Understanding
    • Additional Deployment Options
      • Wolfram Cloud
      • Wolfram Web Engine
      • wolframscript
      • WSTPServer
    • Group & Organizational Licensing
    • All Products
  • Consulting & Solutions
    • Wolfram Consulting

    Data Science, Finance & Business

    • Artificial Intelligence
    • Data Science
    • Healthcare
    • Real Estate

    Engineering

    • Civil Engineering
    • Automotive Engineering
    • Sustainable Energy

    Science & Technology

    • AgTech
    • Biosciences
    • Environmental Science
    • Food Science
    • Quantum Computation
    • Social and Behavioral Sciences

    More Wolfram Solutions

    Technology for Education

    • Research Universities
    • Colleges & Teaching Universities
    • High Schools
    • Resources for Students

    Education Initiatives

    • Next-Gen EdTech
    • Computer-Based Math

    More Solutions for Education

    • Contact Us
  • Learning & Support

    Get Started

    • Wolfram Language Introduction
    • Fast Intro for Programmers
    • Fast Intro for Math Students
    • Wolfram Language Documentation

    Grow Your Skills

    • Wolfram U

      Courses in computing, science, life and more

    • Community

      Learn, solve problems and share ideas.

    • Blog

      News, views and insights from Wolfram

    • Resources for

      Software Developers
    • Tech Support
      • Contact Us
      • Support FAQs
    • More Learning
      • Highlighted Core Areas
      • Demonstrations
      • YouTube
      • Daily Study Groups
      • Wolfram Schools and Programs
      • Books
    • Support FAQs
    • Contact Us
  • Company
    • About Wolfram
    • Career Center
    • All Sites & Resources
    • Connect & Follow
    • Contact Us

    Work with Us

    • Student Ambassador Initiative
    • Wolfram for Startups
    • Student Opportunities
    • Jobs Using Wolfram Language

    Educational Programs for Adults

    • Summer School
    • Winter School

    Educational Programs for Youth

    • Middle School Camp
    • High School Research Program
    • Computational Adventures

    Read

    • Stephen Wolfram's Writings
    • Wolfram Blog
    • Wolfram Tech | Books
    • Wolfram Media
    • Complex Systems
    • Educational Resources
      • Wolfram MathWorld
      • Wolfram in STEM
      • Wolfram Challenges
      • Wolfram Problem Generator
    • Wolfram Initiatives
      • Wolfram Science
      • Wolfram Foundation
      • History of Mathematics Project
    • Events
      • Stephen Wolfram Livestreams
      • Online & In-Person Events
    • Contact Us
    • Connect & Follow
  • For AIs
  • Wolfram Cloud
  • Your Account
  • User Portal
Wolfram Language & System Documentation Center
ParallelTry
  • See Also
    • ParallelMap
    • Parallelize
    • WaitNext
    • $KernelCount
  • Related Guides
    • Parallel Computing
    • Raspberry Pi
    • Managing Remote and Parallel Kernels
  • Workflows
    • Run a Computation in Parallel
    • See Also
      • ParallelMap
      • Parallelize
      • WaitNext
      • $KernelCount
    • Related Guides
      • Parallel Computing
      • Raspberry Pi
      • Managing Remote and Parallel Kernels
    • Workflows
      • Run a Computation in Parallel

ParallelTry[f,{arg1,arg2,…}]

evaluates f[argi] in parallel, returning the first result received.

ParallelTry[f,{arg1,arg2,…},k]

returns a list of the first k results.

Details and Options
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Options  
DistributedContexts  
Applications  
Properties & Relations  
Possible Issues  
See Also
Related Guides
Related Workflows
History
Cite this Page
BUILT-IN SYMBOL
  • See Also
    • ParallelMap
    • Parallelize
    • WaitNext
    • $KernelCount
  • Related Guides
    • Parallel Computing
    • Raspberry Pi
    • Managing Remote and Parallel Kernels
  • Workflows
    • Run a Computation in Parallel
    • See Also
      • ParallelMap
      • Parallelize
      • WaitNext
      • $KernelCount
    • Related Guides
      • Parallel Computing
      • Raspberry Pi
      • Managing Remote and Parallel Kernels
    • Workflows
      • Run a Computation in Parallel

ParallelTry

ParallelTry[f,{arg1,arg2,…}]

evaluates f[argi] in parallel, returning the first result received.

ParallelTry[f,{arg1,arg2,…},k]

returns a list of the first k results.

Details and Options

  • ParallelTry automatically distributes computations among different available kernels and processors.
  • Any evaluations still underway after k results have been received are aborted.
  • If the result from evaluating one of the f[argi] is $Failed, then it is ignored.
  • If no results other than $Failed are obtained, ParallelTry returns $Failed.
  • ParallelTry[f,{arg1,arg2,…}] allocates evaluations of the f[argi] to different kernels and processors, starting with arg1.
  • If there are more argi than kernels, then some of the argi will not be tried unless earlier ones return $Failed.
  • ParallelTry takes the same DistributedContexts option as ParallelTable.

Examples

open all close all

Basic Examples  (2)

Find the factorization of a number that is easy to factorize:

Wolfram Language code: ParallelTry[FactorInteger, Range[10 ^ 20 + 1, 10 ^ 20 + $KernelCount]]

Nondeterministically find a prime in a given range:

Wolfram Language code: ParallelTry[If[PrimeQ[#], #, $Failed]&, Range[10 ^ 100, 10 ^ 100 + 1000]]

Scope  (2)

Return the first two successful results:

Wolfram Language code: ParallelTry[If[PrimeQ[#], #, $Failed]&, Range[10 ^ 100, 10 ^ 100 + 1000], 2] - 10 ^ 100

If too few results are available, the result may be shorter than requested:

Wolfram Language code: ParallelTry[If[PrimeQ[#], #, $Failed]&, Range[10 ^ 100, 10 ^ 100 + 1000], 4] - 10 ^ 100

If no successful results are found, ParallelTry returns $Failed:

Wolfram Language code: ParallelTry[If[PrimeQ[#], #, $Failed]&, Range[10 ^ 100, 10 ^ 100 + 100]]

Options  (5)

DistributedContexts  (5)

By default, definitions in the current context are distributed automatically:

Wolfram Language code: remote[x_] := {$KernelID, x ^ 3}
Wolfram Language code: ParallelTry[remote, {1, 2, 3, 4}]

Do not distribute any definitions of functions:

Wolfram Language code: local[x_] := {$KernelID, x ^ 2}
Wolfram Language code: ParallelTry[local, {1, 2, 3, 4}, DistributedContexts -> None]

Distribute definitions for all symbols in all contexts appearing in a parallel computation:

Wolfram Language code: a`f[x_] := {$KernelID, x}
Wolfram Language code: ParallelTry[a`f, {1, 2, 3, 4}, 2, DistributedContexts -> Automatic]

Distribute only definitions in the given contexts:

Wolfram Language code: b`g[x_] := {$KernelID, -x}
Wolfram Language code: ParallelTry[b`g, {1, 2, 3, 4}, DistributedContexts -> {"a`"}]

Restore the value of the DistributedContexts option to its default:

Wolfram Language code: SetOptions[ParallelTry, DistributedContexts :> $DistributedContexts]

Applications  (5)

Find a random prime in parallel:

Wolfram Language code: ParallelTry[ (While[!PrimeQ[p = RandomInteger[{10 ^ 100, 10 ^ 101}]]];p)&, Range[$ProcessorCount]]

Find an irreducible polynomial with a random search on each parallel kernel:

Wolfram Language code: randPoly[n_Integer ? Positive, x_, p_] := Expand[Fold[x * #1 + #2&, 1, RandomInteger[{0, p - 1}, n]]]
Wolfram Language code: findOne[n_, x_, p_ ? PrimeQ] := Module[{poly}, While[!IrreduciblePolynomialQ[poly = randPoly[n, x, p], Modulus -> p], Null]; poly]
Wolfram Language code: ParallelTry[findOne[100, x, 2]&, Range[$KernelCount]]

Search for a Mersenne prime starting at a given prime exponent:

Wolfram Language code: search[n0_, dn_] := Module[{n = n0}, While[!PrimeQ[2 ^ Prime[n] - 1], n += dn];n]
Wolfram Language code: With[{dn = $KernelCount, n0 = 500}, n = ParallelTry[search[n0 + #, dn]&, Range[0, dn - 1]]; {n, Prime[n]} ]

Try different methods for minimization and return the first one that succeeds:

Wolfram Language code: ParallelTry[ {#, FindMinimum[E^Sin[50 x] + Sin[60 E^y] + Sin[70 Sin[x]] + Sin[Sin[80 y]] - Sin[10 (x + y)] + (1/4) (x^2 + y^2), {x, y}, Method -> #]}&, {"Gradient", "ConjugateGradient", "InteriorPoint", "QuasiNewton", "Newton"}]

Try different symbolic methods of summation and return the first one to succeed:

Wolfram Language code: ParallelTry[(s = Sum[(a^k (-1 + a - k)/(1 + k) k!), k, Method -> #];If[Head@s === Sum, $Failed, s])&, {"Polynomial", "PolynomialExponential", "HypergeometricTermGosper", "PolynomialTrigonometric"}]

In this case, only one method succeeded:

Wolfram Language code: ParallelMap[(s = Sum[(a^k (-1 + a - k)/(1 + k) k!), k, Method -> #];If[Head@s === Sum, $Failed, s])&, {"Polynomial", "PolynomialExponential", "HypergeometricTermGosper", "PolynomialTrigonometric"}]

Properties & Relations  (5)

ParallelTry generally returns the first successful result received:

Wolfram Language code: ParallelTry[(Pause[#];#)&, {4, 3, 2, 1}]

ParallelTry works like ParallelMap, but returns only one of the results:

Wolfram Language code: ParallelMap[f, {a, b, c, d}]
Wolfram Language code: ParallelTry[f, {a, b, c, d}]

ParallelTry is essentially implemented in terms of WaitNext:

Wolfram Language code: parallelTry[f_, args_List] := Module[{evs, ev, res = $Failed}, evs = Composition[ParallelSubmit, f] /@ args; While[res === $Failed && Length[evs] > 0, {res, ev, evs} = WaitNext[evs]]; AbortKernels[]; res ]
Wolfram Language code: parallelTry[FactorInteger, Range[10 ^ 20 + 1, 10 ^ 20 + $KernelCount]]

Functions defined interactively are automatically distributed to all kernels when needed:

Wolfram Language code: ftest[n_] := Labeled[Framed[PrimeQ[2 ^ n - 1]], $KernelID]
Wolfram Language code: ParallelTry[ftest, Range[1275, 1285]]

Distribute definitions manually and disable automatic distribution:

Wolfram Language code: gtest[n_] := Labeled[Framed[PrimeQ[2 ^ n - 1]], $KernelID]
Wolfram Language code: DistributeDefinitions[gtest];
Wolfram Language code: ParallelTry[ftest, Range[1275, 1285], 3, DistributedContexts -> None]

For functions from a package, use ParallelNeeds rather than DistributeDefinitions:

Wolfram Language code: Needs["FiniteFields`"]
Wolfram Language code: Map[FieldSize, Table[GF[2, i], {i, 10}]]
Wolfram Language code: ParallelNeeds["FiniteFields`"]
Wolfram Language code: ParallelTry[FieldSize, Table[GF[2, i], {i, 10}], 4]

Possible Issues  (3)

If there are more expressions than kernels, some will never be tried:

Wolfram Language code: ParallelTry[(Print[#];Pause[RandomReal[]];$KernelID)&, Range[$KernelCount + 1]]

A function used that is not known on the parallel kernels may lead to sequential evaluation:

Wolfram Language code: ptest[n_] := If[PrimeQ[2 ^ n - 1], {n, $KernelID}, $Failed]
Wolfram Language code: ParallelTry[ptest, Range[20, 40], DistributedContexts -> None]

Define the function on all parallel kernels:

Wolfram Language code: DistributeDefinitions[ptest]

The function is now evaluated on the parallel kernels:

Wolfram Language code: ParallelTry[ptest, Range[20, 40], DistributedContexts -> None]

Definitions of functions in the current context are distributed automatically:

Wolfram Language code: qtest[n_] := If[PrimeQ[2 ^ n - 1], {n, $KernelID}, $Failed]
Wolfram Language code: ParallelTry[ptest, Range[20, 70], 2]

Definitions from contexts other than the default context are not distributed automatically:

Wolfram Language code: ctx`ptest[n_] := If[PrimeQ[2 ^ n - 1], {n, $KernelID}, $Failed]
Wolfram Language code: ParallelTry[ctx`ptest, Range[20, 40]]

Use DistributeDefinitions to distribute such definitions:

Wolfram Language code: DistributeDefinitions[ctx`ptest]
Wolfram Language code: ParallelTry[ctx`ptest, Range[20, 40]]

Alternatively, set the DistributedContexts option to include all contexts:

Wolfram Language code: cty`ptest[n_] := If[PrimeQ[2 ^ n - 1], {n, $KernelID}, $Failed]
Wolfram Language code: ParallelTry[cty`ptest, Range[20, 70], 2, DistributedContexts -> Automatic]

See Also

ParallelMap  Parallelize  WaitNext  $KernelCount

Related Guides

    ▪
  • Parallel Computing
  • ▪
  • Raspberry Pi
  • ▪
  • Managing Remote and Parallel Kernels

Related Workflows

    Related Workflows
    ▪
  • Run a Computation in Parallel

History

Introduced in 2008 (7.0) | Updated in 2010 (8.0)

Wolfram Research (2008), ParallelTry, Wolfram Language function, https://reference.wolfram.com/language/ref/ParallelTry.html (updated 2010).

Text

Wolfram Research (2008), ParallelTry, Wolfram Language function, https://reference.wolfram.com/language/ref/ParallelTry.html (updated 2010).

CMS

Wolfram Language. 2008. "ParallelTry." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2010. https://reference.wolfram.com/language/ref/ParallelTry.html.

APA

Wolfram Language. (2008). ParallelTry. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ParallelTry.html

BibTeX

@misc{reference.wolfram_2026_paralleltry, author="Wolfram Research", title="{ParallelTry}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/ParallelTry.html}", note=[Accessed: 01-September-2026]}

BibLaTeX

@online{reference.wolfram_2026_paralleltry, organization={Wolfram Research}, title={ParallelTry}, year={2010}, url={https://reference.wolfram.com/language/ref/ParallelTry.html}, note=[Accessed: 01-September-2026]}

Top
Introduction for Programmers
Introductory Book
Wolfram Function Repository | Wolfram Data Repository | Wolfram Data Drop | Wolfram Language Products
Top
  • Products
  • Wolfram|One
  • Mathematica
  • AI Access
  • Compute Services
  • System Modeler

  • Wolfram|Alpha Notebook Edition
  • Wolfram|Alpha Pro
  • Mobile Apps

  • Wolfram Engine
  • Wolfram Player

  • Volume & Site Licensing
  • Server Deployment Options
  • Consulting
  • Wolfram Consulting
  • Repositories
  • Data Repository
  • Function Repository
  • Community Paclet Repository
  • Neural Net Repository
  • Prompt Repository

  • Wolfram Language Example Repository
  • Notebook Archive
  • Wolfram GitHub
  • Learning
  • Wolfram U
  • Wolfram Language Documentation
  • Webinars & Training
  • Educational Programs

  • Wolfram Language Introduction
  • Fast Introduction for Programmers
  • Fast Introduction for Math Students
  • Books

  • Wolfram Community
  • Wolfram Blog
  • Public Resources
  • Wolfram|Alpha
  • Wolfram Problem Generator
  • Wolfram Challenges

  • Computer-Based Math
  • Computational Thinking
  • Computational Adventures

  • Demonstrations Project
  • Wolfram Data Drop
  • MathWorld
  • Wolfram Science
  • Wolfram Media Publishing
  • Customer Resources
  • Store
  • Product Downloads
  • User Portal
  • Your Account
  • Organization Access

  • Support FAQ
  • Contact Support
  • Company
  • About Wolfram
  • Careers
  • Contact
  • Events
Wolfram Community Wolfram Blog
Legal & Privacy Policy
WolframAlpha.com | WolframCloud.com
© 2026 Wolfram
© 2026 Wolfram | Legal & Privacy Policy |
English