Parallalization of matrix multiply error
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Parallalization of matrix multiply error

  1. #1
    Join Date
    Sep 2016
    Posts
    1

    Question Parallalization of matrix multiply error

    I'm tried to multiply 1000x1000 matrixes with segments. But I get an error..
    Code:
    #include "stdafx.h"
    #include <Windows.h>
    #include <stdio.h>
    #include <iostream>
    #include <process.h>
    #include <stdlib.h>
    #include <math.h>
    #include <chrono>
    
    
    volatile int str = 0;
    const int size = 100;
    const int BLM = 25;
    int **A;//Matrix A
    int **B;//Matrix B
    int **C;//Output Matrix C
    //int matriscarp(int, int);
    //void matrisAtama();
    //void destruct();
    
    using namespace std;
    void matrisAtama(){
    
    //assigning first dimension
    A = new int*[size];
    //Assign second dimension
    for (int i = 0; i < size; i++)
    {
    	A[i] = new int[size];
    }
    //assigning first dimension
    B = new int*[size];
    //Assign second dimension
    for (int i = 0; i < size; i++)
    {
    	B[i] = new int[size];
    }
    
    //assigning first dimension
    C = new int*[size];
    //Assign second dimension
    for (int i = 0; i < size; i++)
    {
    	C[i] = new int[size];
    }
    
    int l = 1, u = 1;
    for (int i = 0; i < size; i++)
    for (int j = 0; j < size; j++)
    {
    	l++;
    	u++;
    	l = l % 9;
    	u = u % 9;
    	A[i][j] = l;
    	B[i][j] = u;
    }
    
    }
    void destruct(){
    	//delete the dynamic memory of A
    	for (int i = 0; i < size; i++)
    	{
    		delete[] A[i];
    	}
    	delete[] A;
    	//delete the dynamic memory of B
    	for (int i = 0; i < size; i++)
    	{
    		delete[] B[i];
    	}
    	delete[] B;
    	//delete the dynamic memory of C
    	for (int i = 0; i < size; i++)
    	{
    		delete[] C[i];
    	}
    	delete[] C;
    }
    
    int matriscarp(int n, int p){
    
    	//auto BslTimer = chrono::high_resolution_clock::now();
    
    	for (int i = 0; i < size; i++)
    	for (int j = 0; j < size; j++)
    	{
    		C[i][j] = 0; //initializing c to zero
    	}
    
    
    	for (int i = n; i < p; i++){
    		cout << endl;
    		for (int j = 0; j < size; j++)
    		{
    			for (int k = 0; k < size; k++){
    				C[j][i] += A[j][k] * B[k][i];
    
    			}
    		}
    	}
    	for (int i = 0; i < size; i++){
    		for (int j = 0; j < size; j++)
    		{
    			cout << C[i][j] << " ";
    
    		}
    	}
    	/*auto BtsTimer = std::chrono::high_resolution_clock::now();
    	auto sure = BtsTimer - BslTimer;
    	printf("Total duration %5d \n", chrono::duration_cast<std::chrono::milliseconds>(sure).count());*/
    	return 1;
    }
    
    
    
    unsigned int __stdcall fFonk(void*){
    
    	auto BslTimer = chrono::high_resolution_clock::now(); //  zamanı başlat
    
    	while (str < size) {
    		int t_str;
    		t_str = str; // şimdiki değerini al 
    		str += BLM;      //ve sıradaki 250 taneyi coz
    		matriscarp(t_str, t_str+BLM);
    			// bulunan sayıları ekrana basabilirsiniz
    			//printf("Thread  no %7d sayi = %8d asal mi = %s\n", GetCurrentThreadId(), j, s);
    		 // her thread 200'li blokları hesaplar
    
    	// her thread kendi süresini yazar
    	auto BtsTimer = std::chrono::high_resolution_clock::now(); // bittikten sonra zamani oku
    	auto sure = BtsTimer - BslTimer; /// farki hesapla
    	printf("Toplam sure %5d ms\n", chrono::duration_cast<std::chrono::milliseconds>(sure).count());
    	return 0;
    }
    }
    int main(int argc, char* argv[]){
    	HANDLE hndl1, hndl2, hndl3, hndl4;
    	matrisAtama();
    
    	hndl1 = (HANDLE)_beginthreadex(0, 0, &fFonk, (void*)0, 0, 0);
    	hndl2 = (HANDLE)_beginthreadex(0, 0, &fFonk, (void*)0, 0, 0);
    	hndl3 = (HANDLE)_beginthreadex(0, 0, &fFonk, (void*)0, 0, 0);
    	hndl4 = (HANDLE)_beginthreadex(0, 0, &fFonk, (void*)0, 0, 0);
    
    	WaitForSingleObject(hndl1, INFINITE);
    	WaitForSingleObject(hndl2, INFINITE);
    	WaitForSingleObject(hndl3, INFINITE);
    	WaitForSingleObject(hndl4, INFINITE);
    
    	CloseHandle(hndl1);
    	CloseHandle(hndl2);
    	CloseHandle(hndl3);
    	CloseHandle(hndl4);
    	destruct();
    	getchar();
    	return 0;
    }
    This is the error i got: Warning 1 warning C4715: 'fFonk' : not all control paths return a value c:\users\consium nullum\documents\visual studio 2013\projects\d3d11_chess\d3d11_chess\xaa\xaa\xaa.cpp 137 1 xaa

  2. #2
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,453

    Re: Parallalization of matrix multiply error

    The warning is correct. If the function is indented
    Code:
    unsigned int __stdcall fFonk(void*)
    {
    	auto BslTimer = chrono::high_resolution_clock::now(); //  zamanı başlat
    
    	while (str < size) {
    		int t_str;
    		t_str = str; // şimdiki değerini al 
    		str += BLM;      //ve sıradaki 250 taneyi coz
    		matriscarp(t_str, t_str+BLM);
    			// bulunan sayıları ekrana basabilirsiniz
    			//printf("Thread  no %7d sayi = %8d asal mi = %s\n", GetCurrentThreadId(), j, s);
                            // her thread 200'li blokları hesaplar
    
    	               // her thread kendi süresini yazar
    	        auto BtsTimer = std::chrono::high_resolution_clock::now(); // bittikten sonra zamani oku
    	        auto sure = BtsTimer - BslTimer; /// farki hesapla
    	        printf("Toplam sure %5d ms\n", chrono::duration_cast<std::chrono::milliseconds>(sure).count());
    	        return 0;
           }
    
    //missing return value here
    
    }
    When the while loop terminates when str >= size, the function does not return a value. Should the return 0 statement be outside of the while loop?
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C, C++ Compiler: Microsoft VS2017.2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)