Search in sources :

Example 66 with Ignite

use of org.apache.ignite.Ignite in project ignite by apache.

the class SparseDistributedMatrix method times.

/**
 * {@inheritDoc}
 */
@Override
public Vector times(Vector vec) {
    if (vec == null)
        throw new IllegalArgumentException("The vector should be not null.");
    if (columnSize() != vec.size())
        throw new CardinalityException(columnSize(), vec.size());
    SparseDistributedMatrix matrixA = this;
    SparseDistributedVector vectorB = (SparseDistributedVector) vec;
    String cacheName = storage().cacheName();
    int rows = this.rowSize();
    SparseDistributedVector vectorC = (SparseDistributedVector) likeVector(rows);
    CacheUtils.bcast(cacheName, () -> {
        Ignite ignite = Ignition.localIgnite();
        Affinity<RowColMatrixKey> affinity = ignite.affinity(cacheName);
        ClusterNode locNode = ignite.cluster().localNode();
        SparseDistributedVectorStorage storageC = vectorC.storage();
        Map<ClusterNode, Collection<RowColMatrixKey>> keysCToNodes = affinity.mapKeysToNodes(storageC.getAllKeys());
        Collection<RowColMatrixKey> locKeys = keysCToNodes.get(locNode);
        if (locKeys == null)
            return;
        // compute Cij locally on each node
        // TODO: IGNITE:5114, exec in parallel
        locKeys.forEach(key -> {
            int idx = key.index();
            Vector Aik = matrixA.getRow(idx);
            vectorC.set(idx, Aik.times(vectorB).sum());
        });
    });
    return vectorC;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) SparseDistributedVectorStorage(org.apache.ignite.ml.math.impls.storage.vector.SparseDistributedVectorStorage) SparseDistributedVector(org.apache.ignite.ml.math.impls.vector.SparseDistributedVector) RowColMatrixKey(org.apache.ignite.ml.math.distributed.keys.RowColMatrixKey) Collection(java.util.Collection) Ignite(org.apache.ignite.Ignite) CardinalityException(org.apache.ignite.ml.math.exceptions.CardinalityException) SparseDistributedVector(org.apache.ignite.ml.math.impls.vector.SparseDistributedVector) Vector(org.apache.ignite.ml.math.Vector)

Example 67 with Ignite

use of org.apache.ignite.Ignite in project ignite by apache.

the class ServiceThreadPoolSelfTest method testDefaultPoolSize.

/**
 * @throws Exception If failed.
 */
public void testDefaultPoolSize() throws Exception {
    Ignite ignite = startGrid("grid", new IgniteConfiguration());
    IgniteConfiguration cfg = ignite.configuration();
    assertEquals(IgniteConfiguration.DFLT_PUBLIC_THREAD_CNT, cfg.getPublicThreadPoolSize());
    assertEquals(IgniteConfiguration.DFLT_PUBLIC_THREAD_CNT, cfg.getServiceThreadPoolSize());
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignite(org.apache.ignite.Ignite)

Example 68 with Ignite

use of org.apache.ignite.Ignite in project ignite by apache.

the class GridSessionCancelSiblingsFromFutureSelfTest method checkTask.

/**
 * @param num Task argument.
 * @throws InterruptedException if failed
 * @throws IgniteCheckedException if failed
 */
private void checkTask(int num) throws InterruptedException, IgniteCheckedException {
    Ignite ignite = G.ignite(getTestIgniteInstanceName());
    ComputeTaskFuture<?> fut = executeAsync(ignite.compute(), GridTaskSessionTestTask.class, num);
    assert fut != null;
    try {
        // Wait until jobs begin execution.
        boolean await = startSig[num].await(WAIT_TIME, TimeUnit.MILLISECONDS);
        assert await : "Jobs did not start.";
        Collection<ComputeJobSibling> jobSiblings = fut.getTaskSession().getJobSiblings();
        // Cancel all jobs.
        for (ComputeJobSibling jobSibling : jobSiblings) {
            jobSibling.cancel();
        }
        Object res = fut.get();
        assert "interrupt-task-data".equals(res) : "Invalid task result: " + res;
        // Wait for all jobs to finish.
        await = stopSig[num].await(WAIT_TIME, TimeUnit.MILLISECONDS);
        assert await : "Jobs did not cancel.";
        int cnt = interruptCnt[num].get();
        assert cnt == SPLIT_COUNT : "Invalid interrupt count value: " + cnt;
    } finally {
        // We must wait for the jobs to be sure that they have completed
        // their execution since they use static variable (shared for the tests).
        fut.get();
    }
}
Also used : Ignite(org.apache.ignite.Ignite) ComputeJobSibling(org.apache.ignite.compute.ComputeJobSibling)

Example 69 with Ignite

use of org.apache.ignite.Ignite in project ignite by apache.

the class GridLog4jCorrectFileNameTest method checkOneNode.

/**
 * Starts the local node and checks for presence of log file.
 * Also checks that this is really a log of a started node.
 *
 * @param id Test-local node ID.
 * @throws Exception If error occurred.
 */
private void checkOneNode(int id) throws Exception {
    try (Ignite ignite = G.start(getConfiguration("grid" + id))) {
        String id8 = U.id8(ignite.cluster().localNode().id());
        String logPath = "work/log/ignite-" + id8 + ".log";
        File logFile = U.resolveIgnitePath(logPath);
        assertNotNull("Failed to resolve path: " + logPath, logFile);
        assertTrue("Log file does not exist: " + logFile, logFile.exists());
        String logContent = U.readFileToString(logFile.getAbsolutePath(), "UTF-8");
        assertTrue("Log file does not contain it's node ID: " + logFile, logContent.contains(">>> Local node [ID=" + id8.toUpperCase()));
    }
}
Also used : Ignite(org.apache.ignite.Ignite) File(java.io.File)

Example 70 with Ignite

use of org.apache.ignite.Ignite in project ignite by apache.

the class GridSessionLoadSelfTest method checkSessionLoad.

/**
 * @throws Exception If failed.
 */
private void checkSessionLoad() throws Exception {
    final Ignite ignite = grid(0);
    assert ignite != null;
    assert ignite.cluster().nodes().size() == 2;
    info("Thread count: " + THREAD_CNT);
    GridTestUtils.runMultiThreaded(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            ComputeTaskFuture f = null;
            try {
                for (int i = 0; i < EXEC_CNT; i++) assertEquals(Boolean.TRUE, (f = executeAsync(ignite.compute().withName("task-name"), SessionLoadTestTask.class, ignite.cluster().nodes().size() * 2)).get(20000));
            } catch (Exception e) {
                U.error(log, "Task failed: " + f != null ? f.getTaskSession().getId() : "N/A", e);
                throw e;
            } finally {
                info("Thread finished.");
            }
            return null;
        }
    }, THREAD_CNT, "grid-load-test-thread");
}
Also used : ComputeTaskFuture(org.apache.ignite.compute.ComputeTaskFuture) Ignite(org.apache.ignite.Ignite) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteException(org.apache.ignite.IgniteException)

Aggregations

Ignite (org.apache.ignite.Ignite)2007 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)358 CountDownLatch (java.util.concurrent.CountDownLatch)238 IgniteCache (org.apache.ignite.IgniteCache)234 IgniteException (org.apache.ignite.IgniteException)216 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)215 Transaction (org.apache.ignite.transactions.Transaction)194 ArrayList (java.util.ArrayList)177 ClusterNode (org.apache.ignite.cluster.ClusterNode)152 UUID (java.util.UUID)137 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)135 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)128 CacheException (javax.cache.CacheException)112 Event (org.apache.ignite.events.Event)112 HashMap (java.util.HashMap)105 List (java.util.List)89 IgniteEx (org.apache.ignite.internal.IgniteEx)85 Map (java.util.Map)84 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)81 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)78