Intel® oneAPI Data Parallel C++
Support for Intel® oneAPI DPC++ Compiler, Intel® oneAPI DPC++ Library, Intel ICX Compiler , Intel® DPC++ Compatibility Tool, and GDB*

if the array size changed after function, how to do with parallel loop ?

bo__john
Beginner
1,015 Views

if the array size changed after function, how to do with parallel loop ?

Please give a complete code, Thank You!

This is a c++ code on common PC,

 

 

#include <iostream>
#include <cstring>
#include <string>
 
using namespace std;

void del_num(string numbers[], int idx, int &size)
{
	int i;
	for(i = idx; i < size - 1; i++)
	{
 
		numbers = numbers[i + 1];
	}
	size--;
 
}

void del_dup(string numbers[], int &size)
{
	int i, j;
	string number;
	for(i = 0; i < size; i++)
	{
		number = numbers;
		for(j = i + 1; j < size; j++)
		{
			if(number == numbers)
			{
 
				del_num(numbers, j, size); j--;	
 
			}
		}
	}
}


  string numbers[] = { "8BCD", "7ED3", "5408", "7684", "804C", 
		"8BCD", "7ED3", "5408", "7684", "80gC", 
		"8BCD", "7ED3", "54e8", "76f4", "804C",
		"8B1D", "7ED3", "5408", "7684", "804C"};
 

int main()
{
 
	
 	int size = sizeof(numbers) / sizeof(numbers[0]); 

 
	
	
		cout << size << "=init _ size " << endl;
		
	del_dup(numbers, size);
	
	for(int i = 0; i < size; i++)
	
	cout << numbers << ' '; cout << endl;
	
	cout << size << "=size " << endl;
	
 
    return 0;
}

 

 

 

 

This is the result :

 

 

$ ./d4
20=init _ size 
8BCD 7ED3 5408 7684 804C 80gC 54e8 76f4 8B1D 
9=size 

 

0 Kudos
3 Replies
RahulV_intel
Moderator
1,015 Views

Hi,

Can you tell us the exact issue that you are facing?

 

Rahul

0 Kudos
bo__john
Beginner
1,015 Views

How to write the those code with parallel loop on (oneapi )dpc++ devcloud platform?

 

the normal parallel loop with a integer value for the size of loop,  if i write array after fuction size of max of loop was changed, how to do it? please give a sample.like code i give on pc. 

 

 

 

 

i needs help please translate my code with parralel loop for the string array  on devcloud linux system use bash with instruction "ssh " to login,  dpc++ compiler.

 full code example like i give at first. please!

 

Please make the parallel loop as a function outside of main() function, code style maybe like that like that :

 

 

#include <CL/sycl.hpp>
#include <iostream>

using namespace std;
using namespace cl::sycl;


 struct myStruct
    {
        int id=1234;
        char a[50];
    };

struct myStruct dt_v1[10];
struct myStruct dt_v2[10];


void abc1(){
    strcpy(dt_v1[0].a, "102755703");
    strcpy(dt_v1[1].a, "ab10");
    strcpy(dt_v1[2].a, "cd10");
    strcpy(dt_v1[3].a, "EF13");
    strcpy(dt_v1[4].a, "5");
    strcpy(dt_v1[5].a, "##184");
    strcpy(dt_v1[6].a, "@@1");
    strcpy(dt_v1[7].a, "&&13");
    strcpy(dt_v1[8].a, "%%14");
    strcpy(dt_v1[9].a, "!!1");

}


void abc2(){
    strcpy(dt_v2[0].a, "102755703");
    strcpy(dt_v2[1].a, "ab10");
    strcpy(dt_v2[2].a, "cd10");
    strcpy(dt_v2[3].a, "EF13");
    strcpy(dt_v2[4].a, "5");
    strcpy(dt_v2[5].a, "##184");
    strcpy(dt_v2[6].a, "@@1");
    strcpy(dt_v2[7].a, "&&13");
    strcpy(dt_v2[8].a, "%%14");
    strcpy(dt_v2[9].a, "!!1");

}


void dpcpp_parallel(){ 
    // ---------SYCL SCOPE STARTS------------
    {
        default_selector device_selector; 
        queue device_queue(device_selector);
        cout<<device_queue.get_device().get_info<info::device::name>()<<std::endl;  //print name of the device it is running on.
        buffer<struct myStruct,1> buff_dt_v1(dt_v1,range<1>{10});
        buffer<struct myStruct,1> buff_dt_v2(dt_v2,range<1>{10});
        device_queue.submit([&](handler &cgh){        
            auto acc_dt_v1 =buff_dt_v1.get_access<access::mode::write>(cgh);        
            auto acc_dt_v2 =buff_dt_v2.get_access<access::mode::write>(cgh); 
            cgh.parallel_for<class StructClass>(range<1>{10},[=](id<1> index){
             struct myStruct* myAcc1=(struct myStruct*)(&acc_dt_v1[index]);
             struct myStruct* myAcc2=(struct myStruct*)(&acc_dt_v2[index]);
            //**************your code logic starts from here**************************
                // to access array "a" use this    
                     char* myArray1=myAcc1->a;
                     char* myArray2=myAcc2->a;
                // To access int "id" use this
                    int myId=myAcc->id;
            });
        });
    }
}

int main(){

    int test1=atoi(dt_v1[4].a);
    std::cout<<"Converting char[] to int "<<test1<<std::endl;
    abc1(); // Initialisation for dt_v1[]
    abc2(); // Initialisation for dt_v2[]
    dpcpp_parallel();    
    return 0;
}

 

thank you!

0 Kudos
RahulV_intel
Moderator
1,015 Views

Hi,

This support is out of our scope. However, we are marking this as a community case so that other users can help you.

 

0 Kudos
Reply